EdgeStream
Stopping the Server
edgeStream.stop() gracefully shuts down all server transports. In-flight pipeline processing completes before the transport disconnects.
Stop Flow
// EdgeStream.stop() — stops all servers concurrently
async stop(): Promise<void> {
if (this.status === 'idle') return;
this.status = 'stopping';
const stopPromises = Array.from(this.servers.values()).map(s => s.stop());
await Promise.all(stopPromises); // all servers stop concurrently
this.status = 'idle';
this.emit('stream:stopped', { timestamp: new Date() });
}
Graceful Application Shutdown
// Cleanup on page unload or component destroy
async function teardownEdgeStream() {
// 1. Unsubscribe all subscriptions first
activeSubscriptions.forEach(sub => sub.unsubscribe());
// 2. Stop EdgeStream
await edgeStream.stop();
console.log('EdgeStream stopped cleanly');
console.log('Status:', edgeStream.status); // 'idle'
}
// React app teardown
useEffect(() => {
return () => {
teardownEdgeStream().catch(console.error);
};
}, []);
React Provider Teardown
The EdgeStreamProvider automatically handles teardown when the provider unmounts. You do not need to call stop() manually when using the React provider:
// EdgeStreamProvider handles this internally
useEffect(() => {
let isMounted = true;
initializeClient().then(() => {
if (!isMounted) return;
setIsInitialized(true);
});
return () => {
isMounted = false;
// Cleanup subscriptions (not transport — let transport manage itself)
};
}, [edgeStreamClient]);
stop() Is Idempotent
Calling
stop() when already idle returns immediately without doing any work.