This could be done with a Pipe class added to a JS function:
use Nesk\Rialto\Data\JsFunction;
use Nesk\Rialto\Data\Pipe;
// Create a new pipe to transfer values from JS to PHP
$pipe = new Pipe;
// Create a JS function with the pipe
$jsFunction = JsFunction::createWithBody("
const value = { foo: 'bar' }
customPipe.sendValue(value)
")->addPipe('customPipe', $pipe);
// Use the JS function with Rialto's implementation...
// Retrieve the transfered values through an iterator
foreach ($pipe as $value) {
var_dump($value); // Outputs: array(1) { 'foo' => string(3) "bar" }
}
Each time the iterator of the Pipe class is called, the next value will be retrieved by communicating with the Node process. Once the value is retrieved, the Node process deletes it and will no longer be available.