Merge pull request #6465 from RoadieHQ/wait-for-unsubscribe
Wait for unsubscribe
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend': patch
|
||||
---
|
||||
|
||||
Unsubscribe from broker after response is flushed
|
||||
@@ -233,17 +233,19 @@ export async function createRouter(
|
||||
);
|
||||
}
|
||||
|
||||
let shouldUnsubscribe = false;
|
||||
for (const event of events) {
|
||||
res.write(
|
||||
`event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`,
|
||||
);
|
||||
if (event.type === 'completion') {
|
||||
unsubscribe();
|
||||
shouldUnsubscribe = true;
|
||||
// Closing the event stream here would cause the frontend
|
||||
// to automatically reconnect because it lost connection.
|
||||
}
|
||||
}
|
||||
res.flush();
|
||||
if (shouldUnsubscribe) unsubscribe();
|
||||
},
|
||||
);
|
||||
// When client closes connection we update the clients list
|
||||
|
||||
Reference in New Issue
Block a user