Created
September 1, 2020 20:23
-
-
Save killreal17/3ea7cdfcc47c06d4da871cd51943b131 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const rejectOnTime = (func, time) => Promise | |
.race([ | |
func, | |
new Promise((res, rej) => { | |
setTimeout(() => rej('Не успел'), time) | |
}) | |
]) | |
const foo = (time) => new Promise ((res, rej) => { | |
setTimeout(() => res('Успел'), time) | |
}) | |
rejectOnTime(foo(1000), 2000).then(console.log, console.log); | |
rejectOnTime(foo(2000), 1000).then(console.log, console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment