The finalize
‘s callback is called during the teardown phase, e.g when the subscriptions are being unsubscribed. This may happen as a result of complete
/error
notifications. The callback’s return value won’t be taken into account.
What you can to instead is to use the endWith
operator. So you could replace finalize
like this:
/* ... */
endWith({type: ResponseType.writeComplete})
/* ... */
As we can see from its implementation
export function endWith<T>(...values: Array<T | SchedulerLike>): MonoTypeOperatorFunction<T> {
return (source: Observable<T>) => concat(source, of(...values)) as Observable<T>;
}
endWith
can take in multiple arguments,
CLICK HERE to find out more related problems solutions.