Created
December 22, 2019 07:56
-
-
Save melvinkcx/d25c985961af700947c0c634f6541b25 to your computer and use it in GitHub Desktop.
Yielding Python Generator from JS in PyWebView: A Dummy Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async *genLogs() { | |
while (true) { | |
yield await window.pywebview.api.gen_logs(); | |
} | |
} | |
const g = genLogs(); | |
(await g.next()).value // 1 | |
(await g.next()).value // 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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