Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use Process module? #28

Open
punund opened this issue Mar 15, 2024 · 4 comments
Open

How to use Process module? #28

punund opened this issue Mar 15, 2024 · 4 comments

Comments

@punund
Copy link

punund commented Mar 15, 2024

Unless I am not seeing something very obvious, why is everything in Process module typed (t, ...) => ...?

Something as seemingly trivial as NodeJs.Process.exit(0) just wouldn't work.

@TheSpyder
Copy link
Owner

This library was written before records mapped to JS objects, so it’s a little more cumbersome than modern ReScript. Fixing that is on my list to do, but that’s a big job.

There is an instance of type t declared at the top of Process. So if you open NodeJS.Process, you can do process->exit(0).

As for why exit takes a t at all? The underlying function does too, nodejs just has an overload to apply to the default process.

we could look at adding a second mapping that applies to the default - that’s very easy to do.

@punund
Copy link
Author

punund commented Mar 16, 2024

Thank you. I prefer not to open modules, so I ended up with

   NodeJs.Process.exitWithCode(NodeJs.Process.process, 0)

which may or may not look a littlte too much for the task :(

What would the alternative mapping look like?

@TheSpyder
Copy link
Owner

I can understand not wanting to open entire modules coming from JS, but ReScript works a bit differently. If you look at the compiled JS it's importing entire modules regardless and only using what it needs to 🤷‍♂️

An alternate binding would be:

@scope("process") external exitDefault: unit => unit = "exit"

If this was added to the Process module here (or if you made one in your own project), Process.exitDefault() will then emit

process.exit();

@TheSpyder
Copy link
Owner

Or, to answer your actual question (sorry about that)

@scope("process") external exitDefaultWithCode: int => unit = "exit"

would then give you Process.exitDefaultWithCode(0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants