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