Last active
November 5, 2015 07:44
-
-
Save AlexTiTanium/d4e5828a4763a68c2b60 to your computer and use it in GitHub Desktop.
Tasks for review Write Promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var domain = require('domain'); | |
// Do not change this function | |
function veryBadFunction(){ | |
setTimeout(function(){ | |
throw new Error('oops!!!'); | |
}, 0) | |
} | |
var d = domain.create(); | |
d.on('error', function(er) { | |
console.log('error'); | |
}); | |
d.run(function(){ veryBadFunction(); }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Реализовать метод `.delay` | |
var foo = function () { | |
console.log("bingo!"); | |
}; | |
foo.delay(300); // после 0.3s: "bingo!" | |
bar.delay(600); // после 0.6s: "Wow!" | |
function bar() { | |
console.log("Wow!"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Реализовать класса Futures | |
function Futures(executor) { | |
} | |
Futures.prototype.then = function () { | |
}; | |
// Тест #1 | |
var foo = new Futures(function (resolve, reject) { | |
resolve(1); | |
}); | |
foo.then(function (val) { | |
console.info("foo.resolved:", val === 1); | |
}, function () { | |
console.assert(false, "foo.resolved"); | |
}); | |
// Тест #2 | |
var bar = new Futures(function (resolve, reject) { | |
setTimeout(resolve.bind(null, 2), 300); | |
setTimeout(reject.bind(null, 3), 200); | |
}); | |
bar.then(function (val) { | |
console.assert(false, "bar.rejected"); | |
}, function (val) { | |
console.info("bar.rejected:", val === 3); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do not change this function | |
function veryBadFunction(){ | |
throw new Error('oops!!!'); | |
} | |
try{ | |
veryBadFunction(); | |
}catch(e){ | |
console.log(e.message); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment