First of all: I highly suggest, that you do refactor your void-functions, other than that, it is kind of possible to use void-functions in a stream, even though it makes no sense whatsoever:
The only thing you can do with void-function in rxjs is the do
-operator and the defer
-operator:
Rx.Observable.defer(() => {
voidFunction1();
voidFunction1();
return Rx.Observable.of("Done");
})
.subscribe(console.log);
function voidFunction1() {
console.log("Called VoidFunc");
// I'm not enjoyed
// because I'm void!
}
<script src="https://unpkg.com/rxjs/bundles/Rx.min.js"></script>
If you have to use forkJoin
:
const voidWrapper$ = wrapVoid(voidFunc);
const voidWrapper2$ = wrapVoid(voidFunc);
Rx.Observable.forkJoin(voidWrapper$, voidWrapper2$)
.subscribe(console.log);
function wrapVoid(func) {
return Rx.Observable.defer(() => {
func();
return Rx.Observable.of("Done");
})
}
function voidFunc() {
console.log("called voidFunc");
// notn' ho!
}
<script src="https://unpkg.com/rxjs/bundles/Rx.min.js"></script>