Cast status property to Status type

This commit is contained in:
Matthieu Louis
2019-02-12 19:03:09 +00:00
parent e8ed1d7fce
commit f9f23a520c
3 changed files with 11 additions and 18 deletions

View File

@@ -3,18 +3,18 @@ import moment from 'moment';
import { Status } from './types';
export class WorkloadService {
export class WorkloadService {
private workLoads: { [key in number]: Work } = {};
private counter = 0;
private getWorkload(id: number): Work | undefined {
return this.workLoads[id];
return this.workLoads[id];
}
private completeWorkload(work: Work) {
work.status = work.id % 2
work.status = work.id % 2
? 'FAILURE'
: 'SUCCESS';
}
@@ -22,8 +22,8 @@ export class WorkloadService {
public create({ complexity }: { complexity: number }) {
const id = this.counter++;
const status = 'WORKING';
const status: Status = 'WORKING';
const milliseconds = complexity * 1000;
const completeDate = moment().add(complexity, 'second').toDate();
const timer = setTimeout(() => this.completeWorkload(work), milliseconds);
@@ -50,7 +50,7 @@ export class WorkloadService {
const work = this.getWorkload(id);
if (!work) return Promise.reject('Workload not found');
if (work.status !== 'WORKING') return Promise.reject('Workload cannot be canceled');
clearTimeout(work.timer)
work.status = 'CANCELED';