summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/rxjs/src/internal/util/Immediate.ts
blob: 161270706d19ab557b2556761406a9bf30ce0772 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let nextHandle = 1;

const tasksByHandle: { [handle: string]: () => void } = {};

function runIfPresent(handle: number) {
  const cb = tasksByHandle[handle];
  if (cb) {
    cb();
  }
}

export const Immediate = {
  setImmediate(cb: () => void): number {
    const handle = nextHandle++;
    tasksByHandle[handle] = cb;
    Promise.resolve().then(() => runIfPresent(handle));
    return handle;
  },

  clearImmediate(handle: number): void {
    delete tasksByHandle[handle];
  },
};