scrivito
Version:
Scrivito is a professional, yet easy to use SaaS Enterprise Content Management Service, built for digital agencies and medium to large businesses. It is completely maintenance-free, cost-effective, and has unprecedented performance and security.
26 lines (21 loc) • 641 B
text/typescript
import { Streamable, Subscription } from 'scrivito_sdk/common';
/** Convert a Promise to a Stream into the promised Stream. */
export function anticipatedStream<T>(
streamPromise: Promise<Streamable<T>>
): Streamable<T> {
return new Streamable((subscriber) => {
let subscription: Subscription | undefined;
streamPromise
.then((stream) => {
if (subscriber.isClosed()) return;
subscription = stream.subscribe(subscriber);
})
.catch((error) => {
subscriber.complete();
throw error;
});
return () => {
if (subscription) subscription.unsubscribe();
};
});
}