llrt icon indicating copy to clipboard operation
llrt copied to clipboard

`process.on` is not implemented

Open floydspace opened this issue 1 year ago • 2 comments

I'd like to gracefully shutdown my lambda

However, looks like LLRT has no process.on('SIGTERM', ... implemented yet

### Tasks
- [ ] implement process.on
- [ ] emit SIGTERM event

floydspace avatar Feb 13 '24 22:02 floydspace

@richarddavison In Node, process is a global instance of EventEmitter, which itself has a wide API surface. Right now, process is implemented as a singleton, ignoring the inherited behavior from EventEmitter. Architecturally, would implementing process.on be a (relatively simple) matter of defining the signals for that method/emitter, or part of a larger effort to implement node:events?

The upside to only implementing process.on (as I see it) is that it significantly reduces the implementation complexity of this issue, which seems fairly important for practical usage in a lambda context; on the other hand, it would introduce more refactoring work and technical debt if/when node:events is ever implemented.

AKushWarrior avatar Feb 14 '24 19:02 AKushWarrior

Hi @AKushWarrior! You are correct. There is no problem migrating process to extend event emitter. The high-level binding lib does not (yet) support this but we can achieve the same effect by using something like eval("class Process extends EventEmitter") from Rust, and add methods to it's prototype.

The tricky part is to asynchronously react to signals. rquickjs in its current state does not expose a mechanism to react to "ticks" asynchronously. But we need to sort this!

richarddavison avatar Feb 14 '24 21:02 richarddavison