import { ResultBackend } from "./result_backend" ; import { createTimeoutPromise } from "./utility" ; /**
 * The result of a task invocation. Asynchronously fetched.
 */ export class Result < T > { private readonly backend : ResultBackend ; private readonly taskId : string ; private readonly result : Promise < T > ; param taskId param backend returns public constructor ( taskId , backend ) { this . taskId = taskId ; this . backend = backend ; this . result = this . getResult ( ) ; } param timeout returns public async get ( timeout ? ) { return createTimeoutPromise ( this . result , timeout ) ; } returns public async delete ( ) { return this . backend . delete ( this . taskId ) ; } returns private async getResult ( ) { const message = await this . backend . get < T > ( { taskId : this . taskId } ) ; return message . result ; } }