Miss any of our Open RFC calls?Watch the recordings here! »

await-done

1.0.10 • Public • Published

await-done

a simple semaphore library that allows you to run async unit tests(in libraries like mocha or jest) and call done()

installation

npm install await-done

usage sample

using simple function

const { callDone, done, semaphore } = require('../lib/async-done');
let counter = 0
  it('should-call-once', async () => {
         setInterval(() => {
            console.log(`counter:${counter}`) //counter:1
            callDone()
        }, 100);
        await done();
 
    }).timeout(1000);
 

it is possible to set the amount until a wait done will be called

 
let counter = 0
  it('should-call-once', async () => {
        setInterval(() => {
            console.log(`counter:${counter}`) //counter:1 counter:2
            callDone()
            counter = counter+1;
        }, 100);
        await done({ doneAmount: 2 });
 
    }).timeout(1000);
 

or by creating a new instance

  it('should-call-once with new instance', async () => {
        const _semaphore = new semaphore();
 
        setTimeout(() => _semaphore.callDone(), 100);
        await _semaphore.done();
 
    }).timeout(1000); 
 

Install

npm i await-done

DownloadsWeekly Downloads

5

Version

1.0.10

License

MIT

Last publish

Collaborators

  • avatar