当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript async.AsyncQueue类代码示例

本文整理汇总了TypeScript中async.AsyncQueue的典型用法代码示例。如果您正苦于以下问题:TypeScript AsyncQueue类的具体用法?TypeScript AsyncQueue怎么用?TypeScript AsyncQueue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了AsyncQueue类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: retryAfter

  retryAfter(task: RequestTask, retryAfter: number, done: Function) {
    this.queue.pause();
    this.queue.unshift(task);
    clearTimeout(this.timeout);

    this.timeout = setTimeout(() => {
      this.queue.resume();
      done();
    }, retryAfter * 1000);
  }
开发者ID:log0ymxm,项目名称:node-harvest,代码行数:10,代码来源:client.ts

示例2: constructor

  constructor(config: any) {
    this.accessToken = config.auth.accessToken;
    this.accountId = config.auth.accountId;

    this.request = Request.defaults({
      baseUrl: 'https://api.harvestapp.com',
      headers: {
        'User-Agent': config.userAgent,
        Authorization: `Bearer ${this.accessToken}`,
        'Harvest-Account-Id': this.accountId,
        'Content-Type': 'application/json'
      },
      transform: this.preprocess
    }) as any;

    // TODO: Make the user agnet required as described on https://help.getharvest.com/api-v2/introduction/overview/general/

    this.concurrency = config.throttleConcurrency || 40;

    // TODO: This needs to be broken down in to smaller chunks.
    this.queue = queue<RequestTask, any>(
      this.requestGenerator(),
      this.concurrency
    );
  }
开发者ID:log0ymxm,项目名称:node-harvest,代码行数:25,代码来源:client.ts

示例3: Error

  /**
   * Get a single object by its id
   *
   * @param {string} objectType - E.g. Person
   * @param {string}objectId - E.g. 52259f95dafd757b06002221
   * @param {object} [params={}] - key/value store for extra arguments like fields, limit, page and/or sort
   * @param {string|null} [versionId=null] - optional versionId to retrieve
   * @returns {Promise} - for object: a key/value object with object data
   */
  getById<T extends CommunibaseDocument = CommunibaseDocument>(
    objectType: CommunibaseEntityType,
    objectId: string,
    params?: CommunibaseParams,
    versionId?: string,
  ): Promise<T> {
    if (typeof objectId !== 'string' || objectId.length !== 24) {
      return Promise.reject(new Error('Invalid objectId'));
    }

    // not combinable...
    if (versionId || (params && params.fields)) {
      const deferred = defer();
      this.queue.push({
        deferred,
        url: `${this.serviceUrl + objectType}.json/${versionId ?
          `history/${objectId}/${versionId}` :
          `crud/${objectId}`}`,
        options: {
          method: 'GET',
          query: params,
        },
      });
      return deferred.promise;
    }

    // cached?
    if (this.cache && this.cache.isAvailable(objectType, objectId)) {
      return this.cache.objectCache[objectType][objectId] as Promise<T>;
    }

    // since we are not requesting a specific version or fields, we may combine the request..?
    if (this.getByIdQueue[objectType] === undefined) {
      this.getByIdQueue[objectType] = {};
    }

    if (this.getByIdQueue[objectType][objectId]) {
      // requested twice?
      return this.getByIdQueue[objectType][objectId].promise;
    }

    this.getByIdQueue[objectType][objectId] = defer();

    if (this.cache) {
      if (this.cache.objectCache[objectType] === undefined) {
        this.cache.objectCache[objectType] = {};
      }
      this.cache.objectCache[objectType][objectId] = this.getByIdQueue[objectType][objectId].promise;
    }

    if (!this.getByIdPrimed) {
      process.nextTick(() => {
        this.spoolQueue();
      });
      this.getByIdPrimed = true;
    }
    return this.getByIdQueue[objectType][objectId].promise;
  }
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:67,代码来源:index.ts

示例4: finalizeInvoice

 /**
  * Finalize an invoice by its ID
  *
  * @param invoiceId
  * @returns {*}
  */
 public finalizeInvoice(invoiceId:string) : Promise<CommunibaseDocument> {
   const deferred = defer();
   this.queue.push({
     deferred,
     url: `${this.serviceUrl}Invoice.json/finalize/${invoiceId}`,
     options: {
       method: 'POST',
     },
   });
   return deferred.promise;
 }
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:17,代码来源:index.ts

示例5: getHistory

 /**
  * Get the history information for a certain type of object
  *
  * VersionInformation:  {
  *    "_id": "ObjectId",
  *    "updatedAt": "Date",
  *    "updatedBy": "string"
  * }
  *
  * @param {string} objectType
  * @param {string} objectId
  * @returns promise for VersionInformation[]
  */
 public getHistory(objectType:CommunibaseEntityType, objectId: string):Promise<CommunibaseVersionInformation[]> {
   const deferred = defer();
   this.queue.push({
     deferred,
     url: `${this.serviceUrl + objectType}.json/history/${objectId}`,
     options: {
       method: 'GET',
     },
   });
   return deferred.promise;
 }
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:24,代码来源:index.ts

示例6: historySearch

 /**
  *
  * @param {string} objectType
  * @param {Object} selector
  * @returns promise for VersionInformation[]
  */
 public historySearch(objectType: CommunibaseEntityType, selector: {}):Promise<CommunibaseVersionInformation[]> {
   const deferred = defer();
   this.queue.push({
     deferred,
     url: `${this.serviceUrl + objectType}.json/history/search`,
     options: {
       method: 'POST',
       body: JSON.stringify(selector),
     },
   });
   return deferred.promise;
 }
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:18,代码来源:index.ts

示例7: undelete

  /**
   * Undelete something from Communibase
   *
   * @param objectType
   * @param objectId
   * @returns promise (for null)
   */
  public undelete(objectType: CommunibaseEntityType, objectId: string):Promise<CommunibaseDocument> {
    const deferred = defer();

    this.queue.push({
      deferred,
      url: `${this.serviceUrl + objectType}.json/history/undelete/${objectId}`,
      options: {
        method: 'POST',
      },
    });

    return deferred.promise;
  }
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:20,代码来源:index.ts

示例8: defer

  /**
   * Get all objects of a certain type
   *
   * @param {string} objectType - E.g. Person
   * @param {object} [params={}] - key/value store for extra arguments like fields, limit, page and/or sort
   * @returns {Promise} - for array of key/value objects
   */
  public getAll<T extends CommunibaseDocument = CommunibaseDocument>
      (objectType: CommunibaseEntityType, params?: CommunibaseParams):Promise<T[]> {
    if (this.cache && !(params && params.fields)) {
      return this.search<T>(objectType, {}, params);
    }

    const deferred = defer();
    this.queue.push({
      deferred,
      url: `${this.serviceUrl + objectType}.json/crud`,
      options: {
        method: 'GET',
        query: params,
      },
    });
    return deferred.promise;
  }
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:24,代码来源:index.ts

示例9: destroy

  /**
   * Delete something from Communibase
   *
   * @param objectType
   * @param objectId
   * @returns promise (for null)
   */
  public destroy(objectType: CommunibaseEntityType, objectId: string):Promise<null> {
    const deferred = defer();

    if (this.cache && this.cache.objectCache && this.cache.objectCache[objectType] &&
      this.cache.objectCache[objectType][objectId]) {
      this.cache.objectCache[objectType][objectId] = null;
    }

    this.queue.push({
      deferred,
      url: `${this.serviceUrl + objectType}.json/crud/${objectId}`,
      options: {
        method: 'DELETE',
      },
    });

    return deferred.promise;
  }
开发者ID:kingsquare,项目名称:communibase-connector-js,代码行数:25,代码来源:index.ts


注:本文中的async.AsyncQueue类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。