fix subscribtions

This commit is contained in:
Pavel Murygin 2021-12-10 16:07:46 +03:00
parent 157d6309c1
commit ba76e4919d

View File

@ -461,9 +461,17 @@ export class FluencePeer {
}), }),
); );
interpreted.pipe( const successful = interpreted.pipe(
// force new line
filter((x) => x.isInterpretationSuccessful),
);
const failed = interpreted.pipe(
// force new line
filter((x) => !x.isInterpretationSuccessful), filter((x) => !x.isInterpretationSuccessful),
tap((item) => );
failed.subscribe((item) =>
setTimeout(() => { setTimeout(() => {
item.onStageChange({ item.onStageChange({
stage: 'interpreterError', stage: 'interpreterError',
@ -471,39 +479,35 @@ export class FluencePeer {
}); });
return; return;
}, 0), }, 0),
),
); );
interpreted.pipe( successful.subscribe((item) =>
filter((x) => x.isInterpretationSuccessful),
tap((item) =>
setTimeout(() => { setTimeout(() => {
item.onStageChange({ stage: 'interpreted' }); item.onStageChange({ stage: 'interpreted' });
}, 0), }, 0),
),
); );
interpreted.pipe( successful
filter((x) => x.isInterpretationSuccessful), .pipe(
// force new line
filter((x) => x.hasPeerPks), filter((x) => x.hasPeerPks),
tap((item) => { )
.subscribe((item) => {
const newParticle = item.particle.clone(); const newParticle = item.particle.clone();
newParticle.data = item.newData; newParticle.data = item.newData;
this._outgoingParticles.next({ ...item, particle: newParticle }); this._outgoingParticles.next({ ...item, particle: newParticle });
}), });
);
interpreted.pipe( successful
filter((x) => x.isInterpretationSuccessful),
filter((x) => !x.hasCallRequests),
tap((item) => {
item.onStageChange({ stage: 'localWorkDone' });
}),
);
interpreted
.pipe( .pipe(
filter((x) => x.isInterpretationSuccessful), // force new line
filter((x) => !x.hasCallRequests),
)
.subscribe((item) => {
item.onStageChange({ stage: 'localWorkDone' });
});
const readyToSend = successful.pipe(
filter((x) => x.hasCallRequests), filter((x) => x.hasCallRequests),
concatMap((item) => item.interpreterResult.callRequests.map(([key, cr]) => [item, key, cr] as const)), concatMap((item) => item.interpreterResult.callRequests.map(([key, cr]) => [item, key, cr] as const)),
map(([item, key, cr]) => { map(([item, key, cr]) => {
@ -540,8 +544,9 @@ export class FluencePeer {
return { particle: newParticle, onStageChange: item.onStageChange }; return { particle: newParticle, onStageChange: item.onStageChange };
}), }),
) );
.subscribe((item) => particlesQueue.next(item));
readyToSend.subscribe((item) => particlesQueue.next(item));
return particlesQueue; return particlesQueue;
} }