Merge pull request #6465 from RoadieHQ/wait-for-unsubscribe

Wait for unsubscribe
This commit is contained in:
Ben Lambert
2021-07-14 10:35:40 +02:00
committed by GitHub
2 changed files with 8 additions and 1 deletions
+5
View File
@@ -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