當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript async.whilst函數代碼示例

本文整理匯總了TypeScript中async.whilst函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript whilst函數的具體用法?TypeScript whilst怎麽用?TypeScript whilst使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了whilst函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: addResults

    //-----------------------------------------------------
    // Add results to an inprogress test run 
    // - testrunID: number - runId against which results are to be published 
    // - testRunResults: TestRunResult[] - testresults to be published  
    //-----------------------------------------------------
    public addResults(testRunId: number, testResults: ifm.TestRunResult[]) : Q.Promise<ifm.TestRunResult[]> {
        var defer = Q.defer();
        var _this = this;

        var i = 0;
        var batchSize = 100; 
        var returnedResults;
        async.whilst(
            function () {
                return i < testResults.length; 
            },
            function (callback) {
                var noOfResultsToBePublished = batchSize; 
                if (i + batchSize >= testResults.length) {
                    noOfResultsToBePublished = testResults.length - i;
                }
                var currentBatch = testResults.slice(i, i + noOfResultsToBePublished);
                i = i + batchSize;

                var _callback = callback;
                _this.service.createTestRunResult(testRunId, currentBatch).then(function (createdTestResults) {
                    returnedResults = createdTestResults;
                    setTimeout(_callback, 10);
                },
                function (err) {
                    defer.reject(err);
                }); 
            },
            function (err) {
                defer.resolve(returnedResults); 
        });

        return defer.promise;
    } 
開發者ID:itsananderson,項目名稱:vso-agent,代碼行數:39,代碼來源:testrunpublisher.ts

示例2: function

 lookup.model.find({}, {}, {lean: true}, function (err, findResults) {
   if (err) {
     cb(err);
   } else {
     // TODO - this ref func can probably be done away with now that list fields can have ref
     var j = 0;
     async.whilst(
       function() { return j < findResults.length; },
       function(cbres) {
         var theResult = findResults[j];
         translateObject.translations[j] = translateObject.translations[j] || {};
         var theTranslation = translateObject.translations[j];
         j++;
         self.getListFields(lookup, theResult, function(err, description) {
           if (err) {
             cbres(err);
           } else {
             theTranslation.value = theResult._id;
             theTranslation.display = description;
             cbres(null);
           }
         })
       },
       cb
     );
   }
 });
開發者ID:zettacristiano,項目名稱:forms-angular,代碼行數:27,代碼來源:data_form.ts

示例3: fillCache

  /**
   * Creates a new CacheDriver with a MemoryCache and fills it with test entries.
   * @param  {int}   numEntries The total number of entries that should be in the cache
   * @param  {int}   numMrrt    The number of tokens in the cache that should be mrrt tokens.  This number must
   *                            be smaller than numEntries.
   * @param  {Function} callback   returns an object with the CacheDriver etc...
   */
  function fillCache(numEntries: any, numMrrt: any, addExpired: any, callback: any) {
    var fakeTokenRequest = util.createEmptyADALObject();

    var memCache = new MemoryCache();
    var authority = cp.authorityTenant;

    var responses: any = [];
    var divisor = Math.floor(numEntries / numMrrt);
    var finalMrrt: any;
    var expiredEntry: any;
    for (var i = 0; i < numEntries; i++) {
      var responseOptions: any = { authority : cp.authorityTenant};
      if (numMrrt && ((i + 1) % divisor) === 0) {
        responseOptions.mrrt = true;
      } else if (addExpired) {
        responseOptions.expired = expiredEntry ? false : true;
      }
      var newResponse = util.createResponse(responseOptions, i);
      finalMrrt = responseOptions.mrrt ? newResponse.refreshToken : finalMrrt;
      expiredEntry = responseOptions.expired ? newResponse : expiredEntry;
      responses.push(newResponse);
    }

    var count = 0;
    var finalRefreshToken: any;
    async.whilst(
      function() { return count < numEntries; },
      function(callback: any) {
        var resource = responses[count].resource;
        var clientId = responses[count].clientId;
        var cacheDriver = new CacheDriver(fakeTokenRequest._callContext, authority, resource, clientId, memCache, unexpectedRefreshFunction);
        var responseToAdd = _.clone(responses[count].decodedResponse);
        cacheDriver.add(responseToAdd, function(err: any) {
          count++;
          process.nextTick(function() {
            callback(err);
            return;
          });
        });
      },
      function(err: any) {
        var cachedResponses = [];
        for (var j = 0; j < responses.length; j++) {
          cachedResponses.push(responses[j].cachedResponse);
        }

        var testValues = {
          cachedResponses : cachedResponses,
          memCache : memCache,
          finalMrrt : finalMrrt,
          fakeTokenRequest : fakeTokenRequest,
          authority : authority,
          expiredEntry : expiredEntry
        };

        callback(err, testValues, finalRefreshToken);
      }
    );
  }
開發者ID:AzureAD,項目名稱:azure-activedirectory-library-for-nodejs,代碼行數:66,代碼來源:cache-driver.ts

示例4: flushUpdatesWithStore

 flushUpdatesWithStore(done: ()=>void) {
     // This is flushUpdates, but we've waited for the initial store to
     // be ready.
     let test = () => { return this.updates.length > 0; };
     let go = (done: ()=>void) => {
         var update = this.updates.shift();
         if (!update) {
             return done();
         }
         this.flushOneUpdate(update, done);
     };
     // note that more updates might get added while this is running
     async.whilst(test, go, (err) => {done();});
 }
開發者ID:drewp,項目名稱:homepage,代碼行數:14,代碼來源:streamed-graph.ts

示例5: function

var slicePerform = function (sliceTimeInMS, waiTimeInMS, test, fn, callback) {
    let allStartTime  = clock()
    let goon          = true
    let sliceTimeInNS = sliceTimeInMS * 1000000
    async.whilst(
        () => goon,
        (next) => {
            let sliceStartTime = clock()
            while (true) {
                if (!test()) {
                    goon = false
                    break
                }
                fn()
                let duration = clock() - sliceStartTime
                if (duration >= sliceTimeInNS) break
            }
            setTimeout(next, waiTimeInMS)
        },
        () => {
            callback(clock() - allStartTime)
        }
    )
}
開發者ID:valaxy,項目名稱:slice-perform,代碼行數:24,代碼來源:index.ts


注:本文中的async.whilst函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。