nikhilk / node-tensorflow

Node.js + TensorFlow
Apache License 2.0
587 stars 59 forks source link

sync vs async #17

Open ralphtheninja opened 6 years ago

ralphtheninja commented 6 years ago

So the session.run() operation is synchronous. If this can take a lot of time it doesn't really play nice with the node way of doing things.

// Run to evaluate and retrieve the value of the 'result' op.
let outputs = session.run(/* inputs */ null,
                          /* outputs */ [ 'result' ],
                          /* targets */ null);

// Should print out '42'
console.log(outputs.result.toValue());

Is it possible to make operations like this async using node-ffi?

ralphtheninja commented 6 years ago

Ideally session.run() should take a callback as last argument or it could return a Promise which resolves to result.

nikhilk commented 6 years ago

Agree; need to see if we can make this work with ffi, and add a runAsync that returns a Promise.

If we can't with just ffi it may be an interesting feature request for the TensorFlow C API.

nikhilk commented 6 years ago

This seems simpler than I thought it might have been with what ffi supports -- for reference: https://github.com/node-ffi/node-ffi/wiki/Node-FFI-Tutorial#async-library-calls