Skip to content

Instantly share code, notes, and snippets.

@xemoe
Last active August 29, 2015 14:08
Show Gist options
  • Save xemoe/67283a38b89680c084c2 to your computer and use it in GitHub Desktop.
Save xemoe/67283a38b89680c084c2 to your computer and use it in GitHub Desktop.
Simple promise
function n() {
var t = this;
t.yet = false;
t.done = function(cb) {
if (!t.yet) {
setTimeout(function(){t.done(cb)}, 1000);
} else {
cb();
}
};
t.do = function() {
setTimeout(function() {
console.log('Do');
t.yet = true;
}, 3000);
return t
};
return t;
}
var g = new n;
g.do().done(
function(){ console.log(1); }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment