I have build a class "Queue" in node.js. I need some queues, so i make instances like "orderQueue": var orderQueue = new queue();
.
When the last element in a queue was processed, the queue should emit a signal like "orderQueue-processed" process.emit(instance.name + "-processed");
, which should be handled by my main program process.on(myobject.name + "-processed", function(){ addmorework ();});
But up to now i have not found out how i can get the name of the instance. Answers in stackoverflow do something with the window object, but it's not a bowser, it's node.js.
May be the idea to use the name is not good. A recommendation what to use instead and is easy to handle would be also very welcome.
There are two possible approaches to this that don't involved the name of the queue.
have your queue object act as an
EventEmitter
, so your main program creates instances of the queue, and then registers an event listener on it:Or, pass the object object as the event data:
so the event listener is given the queue that emitted the event.