diff --git a/src/pyj/srv.pyj b/src/pyj/srv.pyj index e0d60f1b3c..8ee9a8bba2 100644 --- a/src/pyj/srv.pyj +++ b/src/pyj/srv.pyj @@ -1,6 +1,6 @@ # vim:fileencoding=utf-8 # License: GPL v3 Copyright: 2015, Kovid Goyal -# globals: ρσ_get_module +# globals: ρσ_get_module, self from __python__ import hash_literals import initialize # noqa: unused-import @@ -13,6 +13,15 @@ autoreload_enabled = False AUTO_UPDATE_THRESHOLD = 1000 # millisecs +def worker_main(entry_point): + m = ρσ_get_module(window.iframe_entry_point) + main = m?.main + if main: + main() + else: + console.log('worker entry_point ' + entry_point + ' not found') + + def iframe_main(script): script.parentNode.removeChild(script) # free up some memory script = undefined @@ -58,3 +67,8 @@ if document?: iframe_main(iframe_script) else: toplevel_main() + url = window.URL.createObjectURL(Blob([main_js()]), {'type': 'text/javascript'}) + worker = new window.Worker(url + '#moo') + console.log(worker) +elif self?: + entry_point = self.location.hash[1:] diff --git a/src/pyj/worker.pyj b/src/pyj/worker.pyj new file mode 100644 index 0000000000..2c81ea297c --- /dev/null +++ b/src/pyj/worker.pyj @@ -0,0 +1,15 @@ +# vim:fileencoding=utf-8 +# License: GPL v3 Copyright: 2021, Kovid Goyal +from __python__ import bound_methods, hash_literals + +from book_list.globals import main_js + + +def worker_js_url(entry_point): + if not worker_js_url.ans: + worker_js_url.ans = window.URL.createObjectURL(Blob([main_js()]), {'type': 'text/javascript'}) + return worker_js_url.ans + '#' + entry_point + + +def start_worker(entry_point): + return new window.Worker(worker_js_url(entry_point))