42 lines
848 B
JavaScript
42 lines
848 B
JavaScript
function foo (options) {
|
|
this.producer=options.producer;
|
|
this.data=null;
|
|
this.act = {
|
|
main : function () {
|
|
log('starting',this.producer)
|
|
},
|
|
produce : function () {
|
|
this.data={number:random(1,100)}
|
|
out(['SENSOR',this.data])
|
|
this.data.number++;
|
|
out(['SENSOR',this.data])
|
|
},
|
|
forkme : function () {
|
|
fork({
|
|
producer:false,
|
|
data:null
|
|
});
|
|
},
|
|
consume : function () {
|
|
inp.try(3000, ['SENSOR',_],function (t) {
|
|
this.data=t;
|
|
},true);
|
|
},
|
|
end : function () {
|
|
log('terminate',this.data);
|
|
}
|
|
}
|
|
this.trans = {
|
|
main : produce,
|
|
produce : forkme,
|
|
forkme : function () {
|
|
return this.producer?end:consume
|
|
},
|
|
consume : end,
|
|
}
|
|
this.next=main;
|
|
}
|
|
compile(foo,{verbose:1})
|
|
create('foo',{producer:true})
|
|
start()
|