ProcessEvent(function(){
console.log('start');
this.emit('1', 1);
}).register('1', function(d){
console.log(1, d);
if(d == 1)
this.emit('2', 2);
else
throw new Error('end');
}).register('2', function(d){
console.log(2, d);
this.emit('1', 3);
}).catch(function(error){
console.log(error);
});
new Promise(function(resolve){
console.log('start');
resolve(1);
}).then(function(d){
console.log(1, d);
resolve(2)
}).then(function(d){
console.log(2, d);
resolve(3);
}).then(function(d){
console.log(1, d);
throw new Error('end');
}).catch(function(error){
console.log(error);
});
var p1 = ProcessEvent(function(){
console.log('i am p1');
}).register('a', function(d){
console.log('p1-a', d);
this.emit('b', 'p1-b');
}).register('b', function(d){
console.log('p1-b', d);
this.emit('c', 'p1-c');
}).register('c', function(d){
console.log('p1-c', d);
});
var p2 = ProcessEvent(function(){
console.log('i am p2');
this.emit('a', 'p2-a');
}).register('a', function(d){
console.log('p2-a', d);
this.emit(p1, 'b', 'p2-b');
});