File

projects/wms-framework/src/lib/baseframework/TaskCompletionSource.ts

Description

Task completion source class

Index

Properties
Methods

Constructor

Public constructor()

Properties

Public task
Type : Task<T>
Default value : new Task<T>()

The task

Methods

setException
setException(value?: any)

Sets exception

Parameters :
Name Type Optional
value any Yes
Returns : void
setResult
setResult(value?: any)

Sets result

Parameters :
Name Type Optional
value any Yes
Returns : void
Task
Task()

Task promise

Returns : Promise<T>
import { Task } from './Task';

/*****************************************************************************
 * Copyright (C) Mobilize.Net <info@mobilize.net> - All Rights Reserved
 *
 * This file is part of the Mobilize Frameworks, which is
 * proprietary and confidential.
 *
 * NOTICE:  All information contained herein is, and remains
 * the property of Mobilize.Net Corporation.
 * The intellectual and technical concepts contained herein are
 * proprietary to Mobilize.Net Corporation and may be covered
 * by U.S. Patents, and are protected by trade secret or copyright law.
 * Dissemination of this information or reproduction of this material
 * is strictly forbidden unless prior written permission is obtained
 * from Mobilize.Net Corporation.
 ******************************************************************************/

/**
 * Task completion source class
 *
 * @export
 * @class TaskCompletionSource
 * @template T
 * @wType System.Threading.Tasks.TaskCompletionSource`1
 */
export class TaskCompletionSource<T> {
  /**
   * The task
   *
   * @type {Task<T>}
   * @memberof TaskCompletionSource
   * @wProperty Task
   */
  public task: Task<T> = new Task<T>();
  public constructor() {}

  /**
   * Sets exception
   *
   * @param {*} [value]
   * @memberof TaskCompletionSource
   * @wMethod SetException
   */
  setException(value?: any) {
    this.task.reject(value);
  }

  /**
   * Sets result
   *
   * @param {*} [value]
   * @memberof TaskCompletionSource
   * @wMethod SetResult
   */
  setResult(value?: any) {
    this.task.resolve(value);
  }

  /**
   * Task promise
   *
   * @returns {Promise<T>}
   * @memberof TaskCompletionSource
   * @wIgnore
   */
  Task(): Promise<T> {
    if (this.task == null || this.task === undefined) {
      this.task = new Task<T>();
    }
    return this.task.promise;
  }
}

result-matching ""

    No results matching ""