Skip to content

Instantly share code, notes, and snippets.

@killreal17
Created September 1, 2020 20:23
Show Gist options
  • Save killreal17/3ea7cdfcc47c06d4da871cd51943b131 to your computer and use it in GitHub Desktop.
Save killreal17/3ea7cdfcc47c06d4da871cd51943b131 to your computer and use it in GitHub Desktop.
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