dojox/lang/async.js

  • Provides:

    • dojox.lang.async
  • async

    • summary
  • opts

    • summary
  • async.seq

    • type
      Function
    • parameters:
      • x: (typeof )
    • source: [view]
        var fs = opts.call(x) == "[object Array]" ? x : arguments;
        return function(init){
         var x = new Deferred();
         each(fs, function(f){ x.addCallback(f); });
         x.callback(init);
         return x;
        };
    • summary
      Executes functions sequentially. Waits if any of them returns Deferred.
    • chains:
      • opts: (call)
  • async.par

    • type
      Function
    • parameters:
      • x: (typeof )
    • source: [view]
        var fs = opts.call(x) == "[object Array]" ? x : arguments;
        return function(init){
         var results = new Array(fs.length),
          cancel = function(){
           each(results, function(v){
            if(v instanceof Deferred && v.fired < 0){
             v.cancel();
            }
           });
          },
          x = new Deferred(cancel),
          ready = fs.length;
         each(fs, function(f, i){
          var x;
          try {
           x = f(init);
          }catch(e){
           x = e;
          }
          results[i] = x;
         });
         var failed = some(results, function(v){
          if(v instanceof Error){
           cancel();
           x.errback(v);
           return true;
          }
          return false;
         });
         if(!failed){
          each(results, function(v, i){
           if(v instanceof Deferred){
            v.addCallbacks(
             function(v){
              results[i] = v;
              if(!--ready){
               x.callback(results);
              }
             },
             function(v){
              cancel();
              x.errback(v);
             }
            );
           }else{
            --ready;
           }
          });
         }
         if(!ready){
          x.callback(results);
         }
         return x;
        };
    • summary
      Executes functions in parallel. Waits for all of them to finish.
    • chains:
      • opts: (call)
  • async.any

    • type
      Function
    • parameters:
      • x: (typeof )
    • source: [view]
        var fs = opts.call(x) == "[object Array]" ? x : arguments;
        return function(init){
         var results = new Array(fs.length), noResult = true;
          cancel = function(index){
           each(results, function(v, i){
            if(i != index && v instanceof Deferred && v.fired < 0){
             v.cancel();
            }
           });
          },
          x = new Deferred(cancel);
         each(fs, function(f, i){
          var x;
          try {
           x = f(init);
          }catch(e){
           x = e;
          }
          results[i] = x;
         });
         var done = some(results, function(v, i){
          if(!(v instanceof Deferred)){
           cancel(i);
           x.callback(v);
           return true;
          }
          return false;
         });
         if(!done){
          each(results, function(v, i){
           v.addBoth(
            function(v){
             if(noResult){
              noResult = false;
              cancel(i);
              x.callback(v);
             }
            }
           );
          });
         }
         return x;
        };
    • summary
      Executes functions in parallel. As soon as one of them finishes
      cancels the rest.
    • chains:
      • opts: (call)
  • async.select

    • type
      Function
    • parameters:
      • cond: (typeof )
      • x: (typeof )
    • source: [view]
        var fs = opts.call(x) == "[object Array]" ? x : aps.call(arguments, 1);
        return function(init){
         return new Deferred().addCallback(cond).addCallback(function(v){
          if(typeof v == "number" && v >= 0 && v < fs.length){
           return fs[v](init);
          }else{
           return new Error("async.select: out of range");
          }
         }).callback(init);
        };
    • summary
      Executes a condition, waits for it if necessary, and executes
      Nth function from list.
    • chains:
      • opts: (call)
  • async.ifThen

    • type
      Function
    • parameters:
      • cond: (typeof )
      • ifTrue: (typeof )
      • ifFalse: (typeof )
    • source: [view]
        return function(init){
         return new Deferred().addCallback(cond).addCallback(function(v){
          return (v ? ifTrue : ifFalse)(init);
         }).callback(init);
        };
    • summary
      Executes a condition, waits for it if necessary, and executes
      one of two functions.
  • async.loop

    • type
      Function
    • parameters:
      • cond: (typeof )
      • body: (typeof )
    • source: [view]
        return function(init){
         var x, y = new Deferred(function(){ x.cancel(); });
         function ifErr(v){ y.errback(v); }
         function loop(v){
          if(v){
           x.addCallback(body).addCallback(setUp);
          }else{
           y.callback(v);
          }
          return v;
         }
         function setUp(init){
          x = new Deferred().
           addCallback(cond).
           addCallback(loop).
           addErrback(ifErr);
          x.callback(init);
         }
         setUp(init);
         return y;
        };
    • summary
      Executes a condition, waits for it if necessary, and executes
      the body, if truthy value was returned.
      Then it repeats the cycle until the condition function returns
      a falsy value.
  • dojox.lang.async

    • type
      Object
    • summary
  • dojox.lang

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary