Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1
- function scrape(data, cb){
- setTimeout(function(){
- console.log(data);
- if (cb) cb();
- }, 1000);
- }
- function compose(args, cb){
- var l = args.length;
- var i = 0;
- if (l===0) return;
- var next = function(){
- if (i++>=l)
- return cb();
- args[i-1](next);
- };
- next();
- }
- var requests = [
- scrape.bind(null, 'url1'),
- scrape.bind(null, 'url2'),
- scrape.bind(null, 'url3')
- ]
- compose(requests, console.log.bind(console, 'over'));
- //2
- function firstAction(data){
- setTimeout(function(){
- console.log(data[0]);
- secondAction(data);
- }, 1000);
- }
- function secondAction(data){
- setTimeout(function(){
- console.log(data[1]);
- thirdAction(data);
- }, 1000);
- }
- function thirdAction(data){
- setTimeout(function(){
- console.log(data[2]);
- }, 1000);
- }
- firstAction("abc");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement