summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main/expectation.ts
blob: 18fafb2836bcd43fe9a4887629fce8d827ac40ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
export default class Expectation {
  private fulfilled = false;
  private timeout: NodeJS.Timeout;

  constructor(private handler: () => void, timeout = 2000) {
    this.timeout = global.setTimeout(() => {
      this.fulfill();
    }, timeout);
  }

  public fulfill() {
    if (this.fulfilled) {
      return;
    }

    this.fulfilled = true;
    global.clearTimeout(this.timeout);
    this.handler();
  }
}