pastel
pastel copied to clipboard
When does the program exit?
Itβs not entirely obvious when/how the program exits. When rerendering stops and there are no more timeouts or pending async stuff?
(from Twitter conversation)
Pastel or Ink don't handle exiting the process, so it will exit the same way as any other Node.js program, when there are no more async tasks running (timeouts, requests, etc). Another reason for a "hanging" process may be an input that reads process.stdin
for user input. Could you post a minimal code that reproduces the issue?
π Hi! Great question... we're trying to port an already working command to pastel (create-pastel-app) and we were struggling with the same... I think it would be great if this one could be added in the docs! Maybe a FAQ? Anyone? I don't mind opening a PR π Thanks!
Could you post a minimal code that reproduces the issue?
It's not so much that I have a specific issue, it was primarily just a hole in my understanding. You explained it nicely.
@nuragic Do you mind posting a minimal code that reproduces the issue? I will make a note though to explain this behavior in readme ;)
One example I have is when I use monk
in my cli to interact with my mongoDB. The following snippet anywhere in the cli makes it impossible to exit:
const db = monk('localhost/mydb')
I even tried using this:
<AppContext.Consumer>
{(context) => {
const { exit } = context;
setTimeout(exit, 1000)
return <Static>bye</Static>;
}}
</AppContext.Consumer>
But the cli still did not exit. I solved the issue by calling db.close() to terminate properly the mongo connection.
@Apollinaire that's expected, since there was an active mongodb connection. Process will not exit unless all connections are terminated. It's the same behavior as if you weren't using Pastel.
It's absolutely expected, although it's kind of hidden that the cli does not exit because of that. I think that the docs need a warning about this. Is it normal that it still did not exit even with the AppContext.Consumer
exit
method though?
Yeah, that's expected, since exit
only stops rendering your Ink app, not exits the process. See https://github.com/vadimdemedes/ink#exit.
I just use process.exit();