PHP Classes

File: test/test_pipeline.js

Recommend this page to a friend!
  Classes of Nikos M.   PHP Publish Subscribe   test/test_pipeline.js   Download  
File: test/test_pipeline.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Publish Subscribe
Register and call handlers of events by name
Author: By
Last change:
Date: 3 years ago
Size: 1,300 bytes
 

Contents

Class file image Download
"use strict"; var PublishSubscribe = require('../src/js/PublishSubscribe.js'), echo = console.log; echo('PublishSubscribe.VERSION = ' + PublishSubscribe.VERSION); var pbs = new PublishSubscribe( ); pbs.on('topic', function(evt){ echo('Sync Handler 1 on topic'); evt.next(); }); pbs.on('topic', function(evt){ echo('Sync Handler 2 on topic'); evt.next(); }); pbs.on('topic/subtopic', function(evt){ echo('Sync Handler 1 on topic/subtopic'); evt.next(); }); pbs.on('topic/subtopic', function(evt){ echo('Sync Handler 2 on topic/subtopic'); evt.next(); }); pbs.pipeline('topic/subtopic', {}, null, function(evt){ echo('Sync pipeline finished'); }); var pba = new PublishSubscribe( ); pba.on('topic', function(evt){ echo('Async Handler 1 on topic'); setTimeout(function(){evt.next();}, 100); }); pba.on('topic', function(evt){ echo('Async Handler 2 on topic'); setTimeout(function(){evt.next();}, 100); }); pba.on('topic/subtopic', function(evt){ echo('Async Handler 1 on topic/subtopic'); setTimeout(function(){evt.next();}, 100); }); pba.on('topic/subtopic', function(evt){ echo('Async Handler 2 on topic/subtopic'); setTimeout(function(){evt.next();}, 100); }); pba.pipeline('topic/subtopic', {}, null, function(evt){ echo('Async pipeline finished'); });