Tue 27 Aug 00:14:56 CEST 2024

This commit is contained in:
sbosse 2024-08-27 00:15:13 +02:00
parent d33efa35e4
commit 42bfed827f

41
test/producer-consumer.js Normal file
View File

@ -0,0 +1,41 @@
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()