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

Implement Process methods from dart:io #50

Open
jimmyff opened this issue Nov 15, 2018 · 6 comments
Open

Implement Process methods from dart:io #50

jimmyff opened this issue Nov 15, 2018 · 6 comments
Labels

Comments

@jimmyff
Copy link

jimmyff commented Nov 15, 2018

Hey, I'm using this library in the context of a firebase cloud function. I'm trying to utilise imagemagik from the cloud function. In JS this would be exec(...) and with dart:io i'd use Process.run(...). I can't find an alternative in node_io?

Thanks

@pulyaevskiy
Copy link
Owner

Hi, you are right. I haven't had a chance to implement Process interface from dart:io yet.

There are bindings for Node's child_process module in package:node_interop/child_process.dart though.

I can take a look at this later this week or during the weekend. You are also welcome to submit a pull request if you need this sooner.

@jimmyff
Copy link
Author

jimmyff commented Nov 16, 2018

ah okay great, I think package:node_interop/child_process.dart should cover my needs! Thanks very much

@pulyaevskiy pulyaevskiy changed the title exec / Process.run Implement Process methods from dart:io Nov 20, 2018
@jimmyff
Copy link
Author

jimmyff commented Jan 3, 2019

Hey @pulyaevskiy I'm having difficulty with assigning a listener for ChildProcess events. Don't suppose you can see anything obvious?

    final resize = childProcess.spawn('convert', [ ... ]);
    resize
      ..on('error', (error) { ... })
      ..on('close', (int code, String signal) { ...  })
      ..on('exit', (int code, String signal) { ... });

I'm getting the following error:

TypeError: "listener" argument must be a function
    at _addListener (events.js:216:11)
    at ChildProcess.addListener (events.js:276:10)
    at ch.b8 (/user_code/build/node/functions.dart.js:334:29)
    at J.c4 (/user_code/build/node/functions.dart.js:7921:36)
    at /user_code/build/node/functions.dart.js:7823:3
    at oD.a (/user_code/build/node/functions.dart.js:2372:72)
    at oD.$2 (/user_code/build/node/functions.dart.js:2521:23)
    at og.$1 (/user_code/build/node/functions.dart.js:2517:30)
    at nm.c6 (/user_code/build/node/functions.dart.js:3261:23)
    at mH.$0 (/user_code/build/node/functions.dart.js:2844:14)

I've tried using the other EventEmitter methods like once, addListener etc but not having any luck.

Thanks

@pulyaevskiy
Copy link
Owner

pulyaevskiy commented Jan 3, 2019

Hey, yes.

Any function you pass from Dart to JS must be wrapped with allowInterop or allowInteropCaptureThis.

In your example it would be something like:

    final resize = childProcess.spawn('convert', [ ... ]);
    resize
      ..on('error', allowInterop((error) { ... }))
      ..on('close', allowInterop((int code, String signal) { ...  }))
      ..on('exit', allowInterop((int code, String signal) { ... }));

@jimmyff
Copy link
Author

jimmyff commented Jan 4, 2019

Ahh - I did briefly consider that but I assumed that the library would be handling that.

Having said that I had the child_prcess.dart open and could see what it was doing, clearly not got my head in gear for 2019 yet! :)

Thanks

@pulyaevskiy
Copy link
Owner

but I assumed that the library would be handling that.

node_interop package only provides JS interop bindings based on package:js. You can read how bindings work in the docs of that package.

This is why I also created node_io which hides all the complexity of dealing with JS interop by wrapping Node.js APIs with standard dart:io interfaces.

I'll try to find some time for the Process APIs in node_io in the next couple of weeks.

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

No branches or pull requests

2 participants