refactor: wait for save
This commit is contained in:
parent
18734debff
commit
5f139f8960
|
@ -9,6 +9,7 @@ export default class LocalClient extends Client {
|
|||
this.worker.addEventListener('message', (event) => {
|
||||
if (0 === event.data) {
|
||||
this.worker.terminate();
|
||||
this.worker = undefined;
|
||||
return;
|
||||
}
|
||||
this.accept(event.data);
|
||||
|
|
|
@ -36,9 +36,12 @@ export default function PlaySpecific() {
|
|||
if ('local' !== type) {
|
||||
return;
|
||||
}
|
||||
function onBeforeUnload(event) {
|
||||
async function onBeforeUnload(event) {
|
||||
client.disconnect();
|
||||
event.preventDefault();
|
||||
function waitForSave() {
|
||||
return new Promise((resolve) => setTimeout(resolve, 0));
|
||||
}
|
||||
while (client.worker) { await waitForSave(); }
|
||||
}
|
||||
addEventListener('beforeunload', onBeforeUnload);
|
||||
return () => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user