* Creates a debouncer that will wait for the given duration before resolving.
(durationInMilliseconds: number)
| 61 | * Creates a debouncer that will wait for the given duration before resolving. |
| 62 | */ |
| 63 | function debounceForDuration(durationInMilliseconds: number): Debouncer<unknown> { |
| 64 | return (_context, abortSignal) => { |
| 65 | return new Promise((resolve) => { |
| 66 | let timeoutId: ReturnType<typeof setTimeout> | undefined; |
| 67 | |
| 68 | const onAbort = () => { |
| 69 | clearTimeout(timeoutId); |
| 70 | resolve(); |
| 71 | }; |
| 72 | |
| 73 | timeoutId = setTimeout(() => { |
| 74 | abortSignal.removeEventListener('abort', onAbort); |
| 75 | resolve(); |
| 76 | }, durationInMilliseconds); |
| 77 | |
| 78 | abortSignal.addEventListener('abort', onAbort, {once: true}); |
| 79 | }); |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Creates a debouncer that will wait indefinitely, relying on the node to synchronize pending |
no test coverage detected
searching dependent graphs…