Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
small but functioning impl of a promise
function w(){this.state=null;this.c={};this.result={value:null,pending:false};}
w.prototype.toState=function(state,result){this.state=state;if(this.c[state]){var l=this;setTimeout(function(){l.c[state](result)}, 0);}else{this.result.value=result;this.result.pending=12;}}
w.prototype.onState = function(state,c){this.state=state;if(this.result.pending)this.toState(state,this.result.value ) ; }
function w5sec() {
var l = new w();
setTimeout(function(){l.toState("resolve",12);} , 5000)
return l
}
w5sec().onState("resolve",function(value){console.log(value, "resolved" ) } )
@icefapper

This comment has been minimized.

Copy link
Owner Author

@icefapper icefapper commented Sep 28, 2015

small impl for a promise

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