-
Notifications
You must be signed in to change notification settings - Fork 74
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
Promise returned by webview.bind callback never resolves #131
Comments
Yep, this is an issue (or rather, I think, intended behaviour) with the event loop as |
I tried to do this in a somewhat cumbersome way, for fetches that ignore CORS: deno: let fetches = 0
webview.bind('_fetchJSON', (url, options) => {
const f = fetches++
console.log('started fetch', f)
fetch(url, options).then(r => r.json()).then(results => {
console.log('finished fetch', f)
webview.eval(`
window.fetches[${f}] = ${JSON.stringify(results)})
`)
})
return fetches
}) webview: window.fetches = {}
async function fetchJSON (url, options) {
const id = await _fetchJSON(url, options)
console.log('STARTING FETCH', id)
return new Promise((resolve, reject) => {
const i = setInterval(() => {
if (typeof window.fetches[id] !== 'undefined') {
console.log('FETCH COMPLETE', id)
clearInterval(i)
resolve(globalThis.fetches)
}
}, 10)
})
} but the |
@konsumer Here's a working solution for a fetch proxy. Please include an MIT license declaration and my name as author with this code.
|
My issue is that when I return a promise from the callback passed into
webview.bind
, that promise never resolves. Unless I'm missing something it seems like something is blocking the event loop.To reproduce
This should produce the following logs:
Uncommenting the async flag on the callback, the output becomes:
Finally uncommenting the
await Promise.resolve()
results in no logs produced at all.These additions should have no result on the log output. At first I thought that possibly async callbacks were not allowed, but the source for webview.bind seems to explicitly expect the callback may return a promise:
The text was updated successfully, but these errors were encountered: