@sukima wrote:
I’m looking for some advise. I need to make a test waiter but there are two conflicting patterns.
- have a module scoped set/stack/counter and register one waiter then have the code push/increment/etc. the variable.
- 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