You might also get another question regarding the selection of JavaScript here.
We must create the premise function to be able to use callback function via promise.
And actually, just for you to know, previously we had a lot of callback functions because we didn't
have promises.
Then after some time in JavaScript, we migrated fully to promises and now they're supported in JavaScript
by default, which actually means we're not using callbacks that much anymore.
And as you can see here, we have a standard callback function where inside word doing some asynchronous
code and we must write this function to prime this approach, which actually means, for example, we're
using some older library which is based on the callbacks, but the whole code of our project is using
premises.
This is why it makes a lot of sense to make a wrapper and to use this callback function through the
premise.
To do this, we must create a theme which is called promise by function, which actually means the same
function, but wrapped in promise so we can name it from me sci fi.
And this is the typical name in.
I think, fun.
Just like on the top and here, we don't have any arguments.
And inside here we want to call out a sync function.
And when we have a callback, then we want to call our callback from the premise.
This is where here we must return and you promise.
And here inside promise, we have resolve and rechecked, but we will use here on the result because
we don't have any error here.
Now, inside our promise, we can just call the regular icing function and put the call back inside.
And actually, this callback will give us some data back.
This is why here I am right in data and we even don't know what data we're talking about now.
Inside, we want just to cold resolve and Boston site data from our asynchronous function.
In this case, when the synchronous function is done, then our callback will be happening.
And here, insert callback, we're getting data from asynchronous function and we're calling in callback
resolve for this promise that we created.
And most importantly, that this function will return a promise.
This is why we can use it now.
Like this promise?
If I think function, we just call it and it returns as a.
This is why we can right here.
Then we're getting some result and we can do, for example, console.log result.
So we're using this function as a promise, and we've wrapped our async function in promise ify.
Let's check this out.
I'm deployed in the page and as you can see, we're getting back one after some time because here we
have callback with three thousand milliseconds, which actually means we're getting our data after three
seconds and this code is working.
And now everyone in our application, we can use this callback function in promise of triage.