Skip to content

Instantly share code, notes, and snippets.

@melvinkcx
Created December 22, 2019 07:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melvinkcx/d25c985961af700947c0c634f6541b25 to your computer and use it in GitHub Desktop.
Save melvinkcx/d25c985961af700947c0c634f6541b25 to your computer and use it in GitHub Desktop.
Yielding Python Generator from JS in PyWebView: A Dummy Example
async *genLogs() {
while (true) {
yield await window.pywebview.api.gen_logs();
}
}
const g = genLogs();
(await g.next()).value // 1
(await g.next()).value // 2
class JsApi:
"""
`webview.create_window(js_api=JsApi())`
"""
def gen_logs(self, _):
def gen():
x = 1
while True:
yield x
x += 1
if not hasattr(self, 'g'):
self.g = gen()
return next(self.g)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment