Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var Promise = function(wrappedFn, wrappedThis) {
this.then = function(wrappedFn, wrappedThis) {
this.next = new Promise(wrappedFn, wrappedThis);
return this.next;
};
this.run = function() {
wrappedFn.promise = this;
wrappedFn.apply(wrappedThis);
};
this.complete = function() {
if (this.next) {
this.next.run();
}
};
};
Promise.create = function(func) {
if (func.hasOwnProperty('promise')) {
return func.promise;
} else {
return new Promise();
}
};
@peter-moon

This comment has been minimized.

Copy link

commented Jul 22, 2015

sample usage

var foo = function() {
var promise = Promise.create(foo)
async.wait(function() {
promise.complete();
});
return promise;
}

@dopatraman

This comment has been minimized.

Copy link

commented Aug 19, 2015

Doesnt work. Can you please provide a full example?

foo = new Promise(function() {return [1,2,3,4];});

foo()

TypeError: object is not a function

Also doesnt work:

foo.then(function(i) {return i}).complete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.