pastel icon indicating copy to clipboard operation
pastel copied to clipboard

When does the program exit?

Open erikras opened this issue 5 years ago β€’ 9 comments

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)

erikras avatar May 13 '19 07:05 erikras

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?

vadimdemedes avatar May 20 '19 02:05 vadimdemedes

πŸ‘‹ 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!

nuragic avatar May 21 '19 13:05 nuragic

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.

erikras avatar May 21 '19 17:05 erikras

@nuragic Do you mind posting a minimal code that reproduces the issue? I will make a note though to explain this behavior in readme ;)

vadimdemedes avatar May 23 '19 03:05 vadimdemedes

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 avatar May 31 '19 13:05 Apollinaire

@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.

vadimdemedes avatar Jun 01 '19 16:06 vadimdemedes

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?

Apollinaire avatar Jun 03 '19 08:06 Apollinaire

Yeah, that's expected, since exit only stops rendering your Ink app, not exits the process. See https://github.com/vadimdemedes/ink#exit.

vadimdemedes avatar Jun 20 '19 21:06 vadimdemedes

I just use process.exit();

c1495616js avatar May 22 '20 05:05 c1495616js