shamansir / rpd

:ok_hand: A Minimal Engine for creating Node-Based Visual Programming User Interfaces
http://shamansir.github.io/rpd
442 stars 48 forks source link

Node.process should be able to return results to outlets asynchronously #372

Closed shamansir closed 7 years ago

shamansir commented 7 years ago

With Promises or with the same approach as other frameworks do (done function)

shamansir commented 7 years ago

The question is, should outlets send the results always at the same time, just later (sum of the times required for calculations), or separately one by one (so receiving node could trigger several times)

shamansir commented 7 years ago

Actually Kefir library may be used to return values asynchronously, i.e. using fromCallback or fromPromise when returning the outlet, for example:

Rpd.nodetype('test/from-promise', {
    inlets: {
        sendLater: { type: 'core/any '}
    },
    outlets: {
        value: { type: 'core/any '}
    },
    process: function(inlets) {
        var valueToSend = inlets.sendLater;
        return {
            value: Kefir.fromPromise(new Promise(function(resolve, reject) {
                setTimeout(function() { resolve(valueToSend); }, 1000);
            }));
        } 
    }
})