Skip to content

Commit

Permalink
feat(tasks): adds sleep task
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Feb 17, 2021
1 parent 94ed15c commit 1964dc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tasks/create/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './clear';
export * from './log';
export * from './print';
export * from './sleep';
17 changes: 17 additions & 0 deletions src/tasks/create/sleep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Task, Context } from '../../definitions';
import { log } from './log';
import { into } from 'pipettes';

export function sleep(ms: number): Task.Async {
return async (ctx: Context): Promise<void> => {
into(ctx, log('debug', `Sleep for ${ms}ms`));

return new Promise((resolve) => {
const timeout = setTimeout(() => resolve(), ms);
ctx.cancellation.finally(() => {
clearTimeout(timeout);
resolve();
});
});
};
}

0 comments on commit 1964dc8

Please sign in to comment.