Last active
August 29, 2015 14:17
-
-
Save prettycode/1250ccec5fb8cc874d0e to your computer and use it in GitHub Desktop.
Beep function that returns a promise when its done, for Node.js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// problem: beeper uses setTimeouts() for multiple beeps yet has no callback | |
// solution: return a promise for when beeping is done | |
var beeper = require('beeper'), | |
_ = require('lodash'), | |
q = require('q') | |
; | |
function beep(count) { | |
return q.all(_.times(typeof count === 'undefined' ? 1 : count, function (n) { | |
return q.delay(undefined, n * 500).then(beeper); | |
})); | |
} | |
beep().then(process.exit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment