Quantcast
Viewing all articles
Browse latest Browse all 4826

What are the best practises for making your own test waiters?

@sukima wrote:

I’m looking for some advise. I need to make a test waiter but there are two conflicting patterns.

  1. have a module scoped set/stack/counter and register one waiter then have the code push/increment/etc. the variable.
  2. register and unregister a waiter as needed.

What are the pros and cons and what do others recommend?

const runningThings = new Set();
registerWaiter(() => runningThings.size === 0);
export class Foo {
  start() {
    runningThings.add(this);
    this.startAsyncPolling();
  }
  stop() {
    runningThings.delete(this);
    this.stopAsyncPolling();
  }
}

VS

export class Foo {
  start() {
    this.waiterCheck = () => !this.isPolling;
    registerWaiter(this.waiterCheck);
    this.startAsyncPolling();
  }
  stop() {
    unregisterWaiter(this.waiterCheck);
    this.stopAsyncPolling();
  }
}

Posts: 2

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles