Yesterday, A interviewer asked me this question that "How do you give priority to a promise in JS/NodeJS ?".I was like you could use some thing like await or promise.resolve(), but he said that’s not giving priority. Can anyone explain?
>Solution :
So, one possible way of doing this is using setImmediate and process.nextTick()
https://jinoantony.com/blog/setimmediate-vs-process-nexttick-in-nodejs/
setImmediate() and process.nextTick() are two functions which allows us to control the order of execution of our code in the event loop. Both of these functions schedule our callback handlers in the event queue. But they are executed at different phases of the event loop.