"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/q/benchmark/scenarios.js" (8 Mar 2017, 950 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 "use strict";
    2 
    3 var Q = require("../q");
    4 
    5 suite("Chaining", function () {
    6     var numberToChain = 1000;
    7 
    8     bench("Chaining many already-fulfilled promises together", function (done) {
    9         var currentPromise = Q();
   10         for (var i = 0; i < numberToChain; ++i) {
   11             currentPromise = currentPromise.then(function () {
   12                 return Q();
   13             });
   14         }
   15 
   16         currentPromise.then(done);
   17     });
   18 
   19     bench("Chaining and then fulfilling the end of the chain", function (done) {
   20         var deferred = Q.defer();
   21 
   22         var currentPromise = deferred.promise;
   23         for (var i = 0; i < numberToChain; ++i) {
   24             (function () {
   25                 var promiseToReturn = currentPromise;
   26                 currentPromise = Q().then(function () {
   27                     return promiseToReturn;
   28                 });
   29             }());
   30         }
   31 
   32         currentPromise.then(done);
   33 
   34         deferred.resolve();
   35     });
   36 });