Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Future(promise){
- var result;
- promise.then(function(res){
- result = res;
- });
- Object.defineProperties(this, {
- value: {
- get: function(){
- return result;
- }
- }
- });
- }
- var a = new Promise(function(resolve, reject){
- setTimeout(function(){resolve('Hello, Future');}, 500);
- });
- var b = new Future(a);
- console.log('first call: %s', b.value);
- setTimeout(function(){
- var c = b.value;
- console.log(c);
- }, 1000);
- console.log('second call: %s', b.value);
Add Comment
Please, Sign In to add comment