diff --git a/test/producer-consumer.js b/test/producer-consumer.js new file mode 100644 index 0000000..414f609 --- /dev/null +++ b/test/producer-consumer.js @@ -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()