This adds sync feature to page.js.
$ npm install page-sync
var page = require('page');
// You can choose your favorit Promise implementation.
var Promise = require('bluebird');
var pageSync = require('page-sync')
pageSync(page, Promise);
you have to execute next()
when every action completes.
var start = function(ctx, next) {
console.log(ctx.path + ': start');
next();
}
var delay = function(ctx, next) {
console.log(ctx.path + ': delay');
setTimeout(next, 1000);
}
var end = function(ctx, next) {
console.log(ctx.path + ': end');
next();
}
page('/a', start, delay, end);
page('/b', start, delay, end);
// page moves
page('/a');
page('/b');
// output
// /a: start
// /a: delay
// /a: end
// /b: start
// /b: delay
// /b: end