bridgetownrb / node-runner

A simple way to execute Javascript in a Ruby context via Node
MIT License
32 stars 4 forks source link

Support methods that return a Promise #2

Closed kdiogenes closed 5 months ago

kdiogenes commented 1 year ago

Hey,

I'm not much versed in JavaScript, but I think that this can be a good solution:

#{source}

try {
  const args = #{args}
  Promise.resolve(#{func}(...args)).then(result => {
    const output = JSON.stringify(['ok', result, []])
    process.stdout.write(output)
  })
} catch (err) {
  process.stdout.write(JSON.stringify(['err', '' + err, err.stack]))
}

I will write a PR with it, just would like to open the discussion.

Best regards!

kdiogenes commented 1 year ago

Just created a PR: https://github.com/bridgetownrb/node-runner/pull/3

jaredcwhite commented 5 months ago

Thanks @kdiogenes!