projects/wms-framework/src/lib/baseframework/TaskCompletionSource.ts
Task completion source class
Properties |
|
Methods |
Public
constructor()
|
Public task |
Type : Task<T>
|
Default value : new Task<T>()
|
The task |
setException | ||||||
setException(value?: any)
|
||||||
Sets exception
Parameters :
Returns :
void
|
setResult | ||||||
setResult(value?: any)
|
||||||
Sets result
Parameters :
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;
}
}