diff --git a/test/test.ts b/test/test.ts index 9209c94..71ccef7 100644 --- a/test/test.ts +++ b/test/test.ts @@ -86,6 +86,37 @@ tap.test('should receive a message correctly', async (tools) => { await done.promise; }); +interface IDemoReqRes { + method: 'demo', + request: { + wowso: string; + }; + response: { + hereso: string; + }; +} + +tap.test('ReactionRequest and ReactionResponse should work', async () => { + const reactionResponse = new smartuniverse.ReactionResponse({ + channels: [testClientUniverse.getChannel(testChannelData.channelName)], + funcDef: async reqData => { + console.log(reqData); + return { + hereso: 'Hello there' + }; + }, + method: 'demo' + }); + const reactionRequest = new smartuniverse.ReactionRequest({ + method: 'demo' + }); + const reactionResult = await reactionRequest.fire([testClientUniverse2.getChannel(testChannelData.channelName)], { + wowso: 'wowza' + }); + const result = await reactionResult.getFirstResult(); + console.log(result); +}); + tap.test('should disconnect the client correctly', async () => { await testClientUniverse.stop(); }); diff --git a/ts/smartuniverse.classes.reactionrequest.ts b/ts/smartuniverse.classes.reactionrequest.ts index f926098..06086ca 100644 --- a/ts/smartuniverse.classes.reactionrequest.ts +++ b/ts/smartuniverse.classes.reactionrequest.ts @@ -28,7 +28,7 @@ export class ReactionRequest, requestDataArg: T['request'], timeoutMillisArg=60000) { + public async fire(channelsArg: Array, requestDataArg: T['request'], timeoutMillisArg=5000) { const subscriptionMap = new plugins.lik.Objectmap(); const reactionResult = new ReactionResult(); const requestId = plugins.smartunique.shortId(); diff --git a/ts/smartuniverse.classes.reactionresult.ts b/ts/smartuniverse.classes.reactionresult.ts index ca77b4d..22415ff 100644 --- a/ts/smartuniverse.classes.reactionresult.ts +++ b/ts/smartuniverse.classes.reactionresult.ts @@ -2,7 +2,7 @@ import * as plugins from './smartuniverse.plugins'; import { ReactionResponse } from './smartuniverse.classes.reactionresponse'; export class ReactionResult { - private resultSubject = new plugins.smartrx.rxjs.Subject(); + private resultReplaySubject = new plugins.smartrx.rxjs.ReplaySubject(); private endResult: Array = []; private completeDeferred = plugins.smartpromise.defer>(); @@ -13,7 +13,7 @@ export class ReactionResult void) { - return this.resultSubject.subscribe(observerArg); + return this.resultReplaySubject.subscribe(observerArg); } /** @@ -29,7 +29,7 @@ export class ReactionResult(); - const subscription = this.resultSubject.subscribe(result => { + const subscription = this.resultReplaySubject.subscribe(result => { done.resolve(result); subscription.unsubscribe(); }); @@ -40,7 +40,7 @@ export class ReactionResult