smartuniverse/dist_ts/smartuniverse.classes.reactionresult.js

68 lines
3.9 KiB
JavaScript
Raw Permalink Normal View History

2020-09-24 18:13:48 +00:00
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReactionResult = void 0;
const plugins = __importStar(require("./smartuniverse.plugins"));
class ReactionResult {
constructor() {
this.resultReplaySubject = new plugins.smartrx.rxjs.ReplaySubject();
this.endResult = [];
this.completeDeferred = plugins.smartpromise.defer();
this.resultSubscribe(responseArg => {
this.endResult.push(responseArg);
});
}
resultSubscribe(observerArg) {
return this.resultReplaySubject.subscribe(observerArg);
}
/**
* gets the end result as an array of all results
*/
async getEndResult() {
const result = await this.completeDeferred.promise;
return result;
}
/**
* if there is a single respondant, or you are only interested in the first result
*/
async getFirstResult() {
const done = plugins.smartpromise.defer();
const subscription = this.resultReplaySubject.subscribe(result => {
done.resolve(result);
subscription.unsubscribe();
});
return await done.promise;
}
/**
* push a reactionResponse
*/
async pushReactionResponse(responseArg) {
this.resultReplaySubject.next(responseArg);
}
/**
* completes the ReactionResult
*/
async complete() {
this.completeDeferred.resolve(this.endResult);
}
}
exports.ReactionResult = ReactionResult;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnR1bml2ZXJzZS5jbGFzc2Vz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