fix(core): update

This commit is contained in:
Philipp Kunz 2019-09-17 13:57:34 +02:00
parent bd849d347d
commit ddde21925a
3 changed files with 36 additions and 5 deletions

View File

@ -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<IDemoReqRes>({
channels: [testClientUniverse.getChannel(testChannelData.channelName)],
funcDef: async reqData => {
console.log(reqData);
return {
hereso: 'Hello there'
};
},
method: 'demo'
});
const reactionRequest = new smartuniverse.ReactionRequest<IDemoReqRes>({
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();
});

View File

@ -28,7 +28,7 @@ export class ReactionRequest<T extends plugins.typedrequestInterfaces.ITypedRequ
this.method = optionsArg.method;
}
public async fire(channelsArg: Array<UniverseChannel | ClientUniverseChannel>, requestDataArg: T['request'], timeoutMillisArg=60000) {
public async fire(channelsArg: Array<UniverseChannel | ClientUniverseChannel>, requestDataArg: T['request'], timeoutMillisArg=5000) {
const subscriptionMap = new plugins.lik.Objectmap<plugins.smartrx.rxjs.Subscription>();
const reactionResult = new ReactionResult<T>();
const requestId = plugins.smartunique.shortId();

View File

@ -2,7 +2,7 @@ import * as plugins from './smartuniverse.plugins';
import { ReactionResponse } from './smartuniverse.classes.reactionresponse';
export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedRequest> {
private resultSubject = new plugins.smartrx.rxjs.Subject<T['response']>();
private resultReplaySubject = new plugins.smartrx.rxjs.ReplaySubject<T['response']>();
private endResult: Array<T['response']> = [];
private completeDeferred = plugins.smartpromise.defer<Array<T['response']>>();
@ -13,7 +13,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
}
public resultSubscribe(observerArg: (responseArg: T['response']) => void) {
return this.resultSubject.subscribe(observerArg);
return this.resultReplaySubject.subscribe(observerArg);
}
/**
@ -29,7 +29,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
*/
public async getFirstResult() {
const done = plugins.smartpromise.defer<T['response']>();
const subscription = this.resultSubject.subscribe(result => {
const subscription = this.resultReplaySubject.subscribe(result => {
done.resolve(result);
subscription.unsubscribe();
});
@ -40,7 +40,7 @@ export class ReactionResult<T extends plugins.typedrequestInterfaces.ITypedReque
* push a reactionResponse
*/
public async pushReactionResponse(responseArg: T['response']) {
this.resultSubject.next(responseArg);
this.resultReplaySubject.next(responseArg);
}
/**