Browse Source

feat(kept-promise): improve subject

DEV-4541-Go-go-reloaded-synchronous-project-reveiw
nprimo 1 year ago committed by Niccolò Primo
parent
commit
1bc49fe92e
  1. 18
      subjects/devops/kept-promise/README.md

18
subjects/devops/kept-promise/README.md

@ -2,22 +2,20 @@
### Instructions
Thing in your code does not always happen as fast as you would like.
Things in your code do not always happen as fast as you would like.
Sometimes it is important to wait for a function to finish before keep going on.
Sometimes it is important to wait for a function to finish before keep going on. Other times you don't want your code to be blocking while waiting.
Create an asynchronous function `processInfo` in a file `kept-promise.js`. The function `processInfo` will take an asynchronous function as an input, and it will print the message `Ok!` if the return of the input function is zero or a multiple of two, `Error!` otherwise.
The following function can be used as an example of input function for `processInfo`:
```js
const getImportantInfo = _ =>
new Promise(resolve => {
setTimeout(() => resolve(Math.round(Math.random() * 10)), 1000)
})
const getImportantInfo = async _ =>
new Promise(resolve => resolve(Math.round(Math.random() * 10)))
```
> Assume that your function will always get a valid input function
> Assume that your function will always get a valid input function
### Example
@ -46,7 +44,13 @@ Ok!
$
```
### Hints
- It is possible to wait for an asynchronous function with the keyword `await`. Alternatively, it can be clearer to use the method `.then`.
### Notions
- [Introducing asynchronous JavaScript](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Introducing)
- [await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/await)
- [Using promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises)
- [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function)

Loading…
Cancel
Save