Skip to content

Detecting end of work at end of forked process #255

Closed
@jtlapp

Description

@jtlapp

The standard wisdom for ending a node-forked process is to have either the parent or the child detect when the job is done and then explicitly end the child process. Unfortunately, I seem to have a situation where this conventional approach is not available.

I'm using the node-tap module within a fork to run tests. Most people do this by spawning a process, but I'm adding behavior that requires coordinating parent and child. I'd like to use IPC, so I'm forking.

Node-tap defers its work via process.nextTick() and who knows what else. I can't catch the end of work with a setImmediate(), as that happens too soon. It seems that I need to wait for node-tap to tell me that it's done.

But node-tap can't do that. The calling script essentially queues jobs (tests) with each call to node-tap, and node-tap can't know that no more jobs are forthcoming. The best it could possibly do is keep a count of jobs completed and give me that count. Node-tap is popular, and it seems that this feature wasn't needed for anything else, so it would have to be a special request to add support for my forking use-case.

I could solve this problem if node would just tell me when it would normally exit the process were it not forked, without actually exiting the process. "Hey, I'd normally be exiting now, but I'm not gonna, because you forked me." Then node-tap wouldn't need special support for forking.

Is there a way for me to do this? How do I detect the following condition?

  • The process has reached the end of the script AND there is no pending work to do.

Thanks for any help you can offer! (I'm working with the node-tap folks too.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions