Skip to content

Instantly share code, notes, and snippets.

@prettycode
Last active August 29, 2015 14:17
Show Gist options
  • Save prettycode/1250ccec5fb8cc874d0e to your computer and use it in GitHub Desktop.
Save prettycode/1250ccec5fb8cc874d0e to your computer and use it in GitHub Desktop.
Beep function that returns a promise when its done, for Node.js.
// 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