Skip to content

Commit

Permalink
feat(utils): adds isCancelled
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Feb 17, 2021
1 parent 89f1d1f commit 8535df8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './definitions';
export * from './utils';
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './is-cancelled';
13 changes: 13 additions & 0 deletions src/utils/is-cancelled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Context } from '../definitions';

/**
* A promise returning function that will
* resolve with `true` if `context.cancellation`
* has finalized, and `false` otherwise.
*/
export async function isCancelled(context: Context): Promise<boolean> {
return new Promise<boolean>((resolve) => {
context.cancellation.finally(() => resolve(true));
setTimeout(() => resolve(false), 0);
});
}

0 comments on commit 8535df8

Please sign in to comment.