Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
How to give priority to a promise in JS or Node JS?

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?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

you can do promise chaining by this way, to make sure independent promises run in given order one by one:

function later(delay) {
    return new Promise(function(resolve) {
        setTimeout(resolve(delay), delay);
    });
}

//Promise 1:
let p1 = later(100)

//Promise 2:
let p2 = later(200)

//Promise 2:
let p3 = later(300)

p1.then(delay => (console.log(delay))).then(p2.then(delay => console.log(delay)).then(p3.then(delay => console.log(delay))));

//console:
//100
//200
//300
about 4 years ago · Juan Pablo Isaza Report

0

Maybe what he was getting at was that in a pool of promise, priority could be to solely resolve the first one in that pool, which you could do by using Promise.race (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/race)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!