DefinitelyTyped/types/system-task/system-task-tests.ts
llam ac096c0d79
Add new typeing for System Task (#45489)
Co-authored-by: leo lam <leo.lam@uptake.com>
2020-06-23 12:20:55 -04:00

46 lines
1023 B
TypeScript

import * as SystemTask from 'system-task';
const TYPE = 'Demo Task';
const REQUIREASYNCEPROCESS = true;
const DEMOASSET = {
name: 'DEMO ASSET',
async execute(message: string) {
return new Promise((res) => {
setTimeout(() => {
console.log(`Done with ${message}`);
res();
}, 500);
});
}
};
const logMethod = (messageType: string, message: string, detailMessage?: any) => {
console.log(messageType, message, detailMessage);
};
class DemoTask extends SystemTask {
constructor() {
super(TYPE, REQUIREASYNCEPROCESS, logMethod);
}
async insertPreprocessItemsHandler(task: DemoTask): Promise<any> {
if (!task) {
throw new Error('missing task');
}
return [
{...DEMOASSET, name: 'Asset 1' },
{...DEMOASSET, name: 'Asset 2' }
];
}
async processHandler(task: DemoTask, processItem: any): Promise<any> {
await processItem.execute(processItem.name);
return processItem;
}
}
const task: DemoTask = new DemoTask();
task.start();