Bifalgorithm post
Let's see that you have a library that doesn't have promises implemented properly and you will have some somehow to fix this. So for example, we have a function here. Get data. This is actually our function and we'd like to return some data here, but in a specific order. So I'll add setTimeOut. SetTimeOut and here we'll add a weight of one second. Okay, and here I'll just add console.log firstItem. So we want to print this out first and second. Second. Okay. Now after running this, we have an issue here. We can see that the second data is run first on first place and there we have the first data here. So the order is not as we expect. To fix that, we have to add an async function here. So we'll say that this is async and also we have to add await and'll create a new promise, new promise and here we'll add a resolve and now we'll wrap this into this resolve, into this promise, sorry, and after running this we'll just resolve. Okay and now when we run this function here we can see that order is proper.
Let's see that you have a library that doesn't have promises implemented properly and you will have some somehow to fix this. So for example, we have a functio…
Ideas in this flowchart
- Fixing Promise Implementation in Library
- Problem Description
- Library lacks proper promise implementation
- Function: Get Data
- Desired: Return data in specific order
- Current Issue
- Order is incorrect
- Second data appears first
- Solution
- Add async function
- Use await with new Promise
- Wrap in resolve
- Outcome
- Order is correct