Skip to content

Instantly share code, notes, and snippets.

@jimmy-collazos
Last active July 19, 2018 12:31
Show Gist options
  • Save jimmy-collazos/9d75baa9581cd3b20a8ecbc389fa2d43 to your computer and use it in GitHub Desktop.
Save jimmy-collazos/9d75baa9581cd3b20a8ecbc389fa2d43 to your computer and use it in GitHub Desktop.
Helper function - sleep()
/**
* Create Promise pending to resolve after N milliseconds
* Example async-await:
* const { sleep } = require('sleep')
* //...
* it ('Should resolve after 100 millisiconds', async function () {
* let Module = load(path)
* await sleep(100)
* expect (Module.status).to.be.equal('resolved')
* })
*
* Expample promise:
* const { sleep } = require('sleep')
* //...
* it ('Should resolve after 100 millisiconds', function (done) {
* let Module = load(path)
* sleep(100)
* .then(() => expect (Module.status).to.be.equal('resolved'))
* .then(done)
* })
*/
exports.sleep = (time) => new Promise((ok) => setTimeout(ok, time))
/**
* Create Promise pending to resolve after N milliseconds
* Example async-await:
* import { sleep } from 'sleep'
* //...
* it ('Should resolve after 100 millisiconds', async function () {
* let Module = load(path)
* await sleep(100)
* expect (Module.status).to.be.equal('resolved')
* })
*
*
* Expample promise:
* import { sleep } from 'sleep'
* //...
* it ('Should resolve after 100 millisiconds', function (done) {
* let Module = load(path)
* sleep(100)
* .then(() => expect (Module.status).to.be.equal('resolved'))
* .then(done)
* })
*/
export const sleep = (time) => new Promise((ok) => setTimeout(ok, time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment