mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.1 KiB
31 lines
1.1 KiB
5 years ago
|
## Keep Trying Or Giveup
|
||
|
|
||
|
### Instructions
|
||
|
|
||
|
Create a `retry` function, that takes 2 arguments
|
||
|
- a `count`, that tells how many retries must be done
|
||
|
- an async `callback`, that will be call every try
|
||
|
|
||
|
and it return a new function, passing arguments given to the
|
||
|
callback on every tries.
|
||
|
|
||
|
> for count of 3, the function will be called at most 4 times:
|
||
|
> the initial call + 3 retries.
|
||
|
|
||
|
|
||
|
Create a `timeout` function, that takes 2 arguments
|
||
|
- a `delay`, that tells how long to wait
|
||
|
- an async `callback`, that will be call
|
||
|
|
||
|
and it return a new function, passing arguments given to the callback
|
||
|
and either the async callback resolve before the delay is reached,
|
||
|
in that case we return the value from the callback,
|
||
|
or reject an error using the message `"timeout"`
|
||
|
|
||
|
|
||
|
### Notions
|
||
|
|
||
5 years ago
|
- [nan-academy.github.io/js-training/examples/promise.js](https://nan-academy.github.io/js-training/examples/promise.js)
|
||
|
- [devdocs.io/dom/windoworworkerglobalscope/settimeout](https://devdocs.io/dom/windoworworkerglobalscope/settimeout)
|
||
|
- [devdocs.io/javascript/global_objects/promise/race](https://devdocs.io/javascript/global_objects/promise/race)
|