extrabacon / python-shell

Run Python scripts from Node.js with simple (but efficient) inter-process communication through stdio
2.12k stars 224 forks source link

feat: promisify the "run" command #269

Closed NoamGaash closed 1 year ago

NoamGaash commented 2 years ago

that's my humble attempt to solve issue #77 thanks for making and maintaining this repo

NoamGaash commented 2 years ago

@Almenon

NoamGaash commented 2 years ago

I believe I have found a way to support both the legacy callback-based API and the newer promise-based one. I believe my implementation has two main drawbacks:

  1. The promise-based implementation cant support providing both stdout and stderr. a promise cannot be both resolved and rejected.
  2. I didn't find a solution for marking specific argument as deprecated, therefore I abuse the console.warning interface
Almenon commented 1 year ago

Sorry for the delay, I do intend on getting to this eventually.

Almenon commented 1 year ago

The problem with trying to support both approaches is that the typing doesn't work out. If you use .then typescript complains because the return value might not be a promise. There might be some fancy typescript syntax for solving this, but I'm just going to simplify and remove the callback option for the next major release. I'm presuming that's fine?

https://i.imgur.com/3dV1D5p.png

Almenon commented 1 year ago

I'm going to merge this in, publish as v4 so you have your changes, and then make some changes I want to make w/ a v5 release.