(concat(ready$,processPlugins$) as Observable<{
plugged: PluggedModule;
cmdPluginsRes: {
execute: Awaitable<Result<void, void>>;
type: PluginType.Command;
name: string;
description: string;
}[];
}>)
(concat(ready$,processPlugins$) as Observable<{
plugged: PluggedModule;
cmdPluginsRes: {
execute: Result<void, void>;
type: PluginType.Command;
name: string;
description: string;
}[];
}>)
^^ this above snippet is what I want. I just want to resolve execute
in cmdPluginRes
so when I subscribe to the observable it would be easier to deal with the data.
i have this rxjs observable. Inside cmdPluginRes ( an array ), I have a promiseLike property execute. How could i turn this inner promise into its resolved type Result<void,void> ? Result type comes from vultix ts-results.
CodePudding user response:
You can do something like this:
concat(ready$, processPlugins$).pipe(
switchMap(obj => from(obj.cmdPluginRes.execute).pipe(
map(executeResult => ({...obj, execute: executeResult })
))
);
Here we pipe the emission into switchMap
.
switchMap
receives emissions and transforms them to emissions of an "inner observable", which in this case is your "execute" promise.
We use from
to transform the promise to observable, which we can then map
to a copy of the original object with the execute
property replaced with the result.