Skip to content

Instantly share code, notes, and snippets.

@PeterHancock
Created February 28, 2014 13:04
Show Gist options
  • Save PeterHancock/9270706 to your computer and use it in GitHub Desktop.
Save PeterHancock/9270706 to your computer and use it in GitHub Desktop.
async shotgun
//cmd.js
exports.invoke = function(shell, options) {
shell.emit('async', function(resume) {
someAsyncFn(function(result){
shell.log(result);
resume();
});
//app.js
var rl = require('readline'),
shell = ...
var ready = true;
//..constructors ..
rl.on('line', function(userInput) {
shell.execute(userInput);
if (ready) {
rl.prompt();
}
});
shell.on('async', function(fn) {
ready = false;
fn(function(){
ready = true;
rl.prompt();
})
});
@PeterHancock
Copy link
Author

That sounds great! I assume the done event will only be fired at the end of execute if invoke is synchronous

@catdadcode
Copy link

That's correct. catdadcode/shotgun#23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment