File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -273,6 +273,26 @@ globalThis.python.exit = pm.eval("""'use strict';
273273""" )(sys.exit);
274274```
275275
276+ # ## Run Python event-loop
277+
278+ You need an event- loop running to use `setTimeout` and `Promise` <=> `awaitable` coercion.
279+
280+ ```python
281+ import asyncio
282+
283+ async def async_fn():
284+ await pm.eval("""
285+ new Promise((resolve) => setTimeout((...args) => {
286+ console.log(args);
287+ resolve();
288+ }, 1000, 42, "abc")
289+ )
290+ """ )
291+ await pm.eval(" async (x) => await x" )(asyncio.sleep(0.5 ))
292+
293+ asyncio.run(async_fn())
294+ ```
295+
276296# pmjs
277297A basic JavaScript shell, `pmjs` , ships with PythonMonkey. This shell can act as a REPL or run
278298JavaScript programs; it is conceptually similar to the `node` shell which ships with Node.js.
You can’t perform that action at this time.
0 commit comments