mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-03 14:06:25 +01:00
feat(utils): add resolveAfter util
This commit is contained in:
committed by
martin
parent
e8bd8b65fa
commit
5913011798
@@ -49,3 +49,4 @@ export * from './throttler';
|
||||
export * from './extractUrlsFromText';
|
||||
export * from './isFullPath';
|
||||
export * from './asciiUtils';
|
||||
export * from './resolveAfter';
|
||||
|
||||
11
packages/utils/src/resolveAfter.ts
Normal file
11
packages/utils/src/resolveAfter.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { createDeferred } from './createDeferred';
|
||||
|
||||
export const resolveAfter = <T = void>(msec: number, value?: T) => {
|
||||
const { promise, reject, resolve } = createDeferred<T>();
|
||||
const timeout = setTimeout(resolve, msec, value);
|
||||
|
||||
return {
|
||||
promise: promise.finally(() => clearTimeout(timeout)),
|
||||
reject,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user