当前位置: 首页>>代码示例>>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;未经允许,请勿转载。