source: trip-planner-front/node_modules/rxjs/src/internal/util/Immediate.ts@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.0 KB
Line 
1let nextHandle = 1;
2const RESOLVED = (() => Promise.resolve())();
3const activeHandles: { [key: number]: any } = {};
4
5/**
6 * Finds the handle in the list of active handles, and removes it.
7 * Returns `true` if found, `false` otherwise. Used both to clear
8 * Immediate scheduled tasks, and to identify if a task should be scheduled.
9 */
10function findAndClearHandle(handle: number): boolean {
11 if (handle in activeHandles) {
12 delete activeHandles[handle];
13 return true;
14 }
15 return false;
16}
17
18/**
19 * Helper functions to schedule and unschedule microtasks.
20 */
21export const Immediate = {
22 setImmediate(cb: () => void): number {
23 const handle = nextHandle++;
24 activeHandles[handle] = true;
25 RESOLVED.then(() => findAndClearHandle(handle) && cb());
26 return handle;
27 },
28
29 clearImmediate(handle: number): void {
30 findAndClearHandle(handle);
31 },
32};
33
34/**
35 * Used for internal testing purposes only. Do not export from library.
36 */
37export const TestTools = {
38 pending() {
39 return Object.keys(activeHandles).length;
40 }
41};
Note: See TracBrowser for help on using the repository browser.