archives

« Bugzilla Issues Index

#3205 — Pipelines: promises evolved


I think, it would be very good to have the following asyncronous model.

new Pipe(PipeObject)
PipeObject has the following schema
{
init:function(){
//ctor
},
sync:function(syncObj){
//syncObj is obj, whose fields are the input ports and they are true is the signal have come
}
i:{
portA:()=>{},//default implementation, null can be used instead
portB:function(b){.....}//some custom code
......
}
o:outputInterface{
portC:(obj)=>obj;,//postprocessing functions (here is default implementation), null can be used instead
portD:function(){}
......
}
}

new Pipe transforms that PipeObject object into Pipe object with prototype
{
i{
set portA:function(port){this.__portA.bind(port)};//connects output port to port a
get portA:function(){return this.__portA};//allows access to methods of Port object
......
},
o:{
get portC:function(){...},
....
},
trigger:function(){...},
bind:function(){....}
}


InputPort object
{
bind:function(port){},//attaches output port port to input port this
unbind:function(port),
}

So we can create a graph.

function createImgSrc(img){
return new Pipe({
init:function(img){
var canv=document.createElement("CANVAS");
var ctx=canv.getContext("2d");
//ajusting sizes and drawing image
.......
o.image(ctx);
},
o:{ctx:null}
}
});

var src=createImageSource(img);
var edgeDetector=new Pipe({
i:{
ctx:function(ctx){
//edge detection
}
},
o:outputInterface{
ctx:null,
error:null
}
});

var gaussianBlur=new Pipe({
i:{
ctx:function(ctx){
//bluring
}
},
o:outputInterface{
ctx:null,
error:null
}
});

var tween=new Pipe({
sync:function(s){
if(s.ctx1&&s.ctx2&&!s.err){
makeTween()
}
},
i:{
ctx1:function(ctx){
},
ctx2:function(ctx){
},
err:function(){}
},
o:outputInterface{
ctx:null,
error:null
},
makeTween:function(ctx1,ctx2){
....making tweening
o.ctx(ctx);
}
});

var save= new Pipe({
i:{
ctx:function(ctx){
ctx.canvas.toBlobHD((b)=>{window.location.href=URL.createObjectURL(b)});
}
}
});

//binding graph
save.i.ctx=tween.o.ctx;
tween.i.ctx1=gaussianBlur.o.ctx;
tween.i.ctx2=edgeDetector.o.ctx;
tween.i.err=Pipe.Any([edgeDetector.o.err,gaussianBlur.o.err]);
gaussianBlur.i.ctx=src.o.ctx;
edgeDetector.i.ctx=src.o.ctx;
src.trigger();


//Pipes can be bound to each other automatically if they have at least partly compatible interfaces
save.bind(tween);
tween.i.ctx1=gaussianBlur.o.ctx;
tween.i.ctx2=edgeDetector.o.ctx;
tween.i.err=Pipe.Any([edgeDetector.o.err,gaussianBlur.o.err]);
gaussianBlur.bind(src);
edgeDetector.bind(src);
src.trigger();


execution is asynchronic,


inspired by verilog modules https://en.wikibooks.org/wiki/Programmable_Logic/Verilog_Module_Structure


Feature requests should follow the proposal process.