-2

I am doing something in the function(some asynchronous work) for the first request but at the same time a few more requests came, now my thread was working on the function(some asynchronous work) but at the same time node has started processing the new request that has came. so my question is, at a given point of time in code I want to know which request my thread is processing. I have explained the same below.

// requestA came
function fun(){    
    // some work
    fun1();
    fun2();
}

function fun1(){
    // do some 
    // asynchronous work
}

function fun2(){
    // do some more
    // asynchronous work
}
fun();

now suppose 3 concurrent requests came -

requestB, requestC, requestD

Now Suppose at a given point of time I want to know fun2( ) or fun1( ) is running for which request in code. How in code I can know this?

Kunal Pal
  • 545
  • 8
  • 21
  • You will have to code your own entrance and exit data to keep track of whatever it is you want to know (like what operations are underway). Javascript does not provide this info for you. – jfriend00 Sep 10 '19 at 04:08
  • If you want to assure something is done sequentially in your server, then you may have to implement some sort of work queue and while something is processing (some flag you maintain in your server), you just add a new incoming request to the queue and when something finishes processing it picks up the next item in the queue and so on... Your question and title seem aimed at different issues so not really sure exactly what you're asking. Note: serializing all requests on your server will substantially reduce your scalability so this should be done in limited cases only. – jfriend00 Sep 10 '19 at 04:38

1 Answers1

0

process._getActiveHandles() gets you handles that are still alive and

process._getActiveRequests() gets you info about active libuv requests (IIRC).

virender nehra
  • 470
  • 6
  • 12