runtimejs / runtime

[not maintained] Lightweight JavaScript library operating system for the cloud
http://runtimejs.org
Apache License 2.0
1.93k stars 128 forks source link

Inter-isolate streams #33

Closed iefserge closed 9 years ago

iefserge commented 9 years ago

Idea: in addition to RPC function calls implement inter-isolate object streams. Useful to implement proper data flow between applications with less overhead than function calls.

Maybe something like this:

Isolate 1

// create stream with 10 object slots
var stream = isolate.createStream({size: 10});
// .. pass stream to other isolate as regular object

// push can throw if stream buffer is full
// when receiver is unable to process data that fast
// so there is a check
if (stream.canPush()) {
  stream.push({a: 'value'});
}

Isolate 2


// read available data from stream buffer (once)
var maxCount = 10; // 0 = all elements
stream.pull(maxCount, function(type, dataArray) { ... })
// or
stream.pull(maxCount).then(function(type, dataArray) { ... })

Type variable one of { 'data', 'error', 'end' }. In case of error dataArray variable contains error object. When Isolate 2 is ready to receive more data it can call stream.pull() again.

iefserge commented 9 years ago

Pipes are supported, example https://github.com/runtimejs/runtime/blob/ae99938ebde0a0be25260ed86bd6262b83edbf5c/initrd/system/net/tcp/tcpsocket.js#L133