-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait for Chelonia, more error logs #2471
Wait for Chelonia, more error logs #2471
Conversation
78f539f
to
4250b55
Compare
group-income
|
Project |
group-income
|
Branch Review |
2469-missing-pubsub-instance-bug-and-failure-to-recover-pubsub-connection
|
Run status |
|
Run duration | 11m 40s |
Commit |
|
Committer | Ricardo Iván Vieitez Parra |
View all properties for this run ↗︎ |
Test results | |
---|---|
|
0
|
|
0
|
|
10
|
|
0
|
|
111
|
View all changes introduced in this branch ↗︎ |
4250b55
to
b4d04e3
Compare
// Send a 'ready' message to the SW and wait back for a response | ||
// This way we ensure that Chelonia has been set up | ||
await new Promise((resolve, reject) => { | ||
const messageChannel = new MessageChannel() | ||
messageChannel.port1.onmessage = (event) => { | ||
if (event.data.type === 'ready') { | ||
resolve() | ||
} else { | ||
reject(event.data.error) | ||
} | ||
messageChannel.port1.close() | ||
} | ||
messageChannel.port1.onmessageerror = () => { | ||
reject(new Error('Message error')) | ||
messageChannel.port1.close() | ||
} | ||
|
||
navigator.serviceWorker.ready.then((worker) => { | ||
worker.active.postMessage({ | ||
type: 'ready', | ||
port: messageChannel.port2 | ||
}, [messageChannel.port2]) | ||
}).catch((e) => { | ||
reject(e) | ||
messageChannel.port1.close() | ||
}) | ||
}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like boilerplate we could abstract away in a function somewhere.
Can you create a function so that chunk is shortened like so?
await postWorkerMessage(worker, { type: 'ready' })
And if there are any other parts of the app that also do something like this, they can reuse this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could make it into another function, but this particular message is unique in how it's sent, that it expects a response and that it expects a response (sbp
also expects a response, but is handled by a more general-purpose function)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also not entirely general purpose because the handler for onmessage
is custom
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @corrideat !
Closes #2469.
This PR adds more logging to catch Chelonia set up errors, and it adds logic to check that Chelonia has been setup.