Skip to content

Event loop tick id #32397

@ORESoftware

Description

@ORESoftware

Basically looking for an event loop tick id, for this purpose:

const run = (cb) => {

   let isCurrentTick = true;
   process.nextTick(() => {
      isCurrentTick = false;
   });

  doSomeWork(() =>{
      isCurrentTIck ? process.nextTick(cb) : cb();
  });
  
}

this is an optimization that can reduce the memory overhead of servers. It's mostly about convenience, but in some cases very necessary when you don't know for sure if something is being fired asynchronously or not.

so the fix looks like:

const run = (cb) => {

  const currentEventLoopId = process.getEventTickId();

  doSomeWork(() =>{
      currentEventLoopId  === process.getEventTickId() ? process.nextTick(cb) : cb();
  });
  
}

so what I am looking for is an incrementing id for every tick of the event loop. This fix would obviate the need for using process.nexTick calls to store some local boolean variable as in the first code example.

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.questionIssues that look for answers.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions