We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 46d59e5 commit 0b94ff3Copy full SHA for 0b94ff3
1 file changed
README.md
@@ -273,6 +273,26 @@ globalThis.python.exit = pm.eval("""'use strict';
273
""")(sys.exit);
274
```
275
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
296
# pmjs
297
A basic JavaScript shell, `pmjs`, ships with PythonMonkey. This shell can act as a REPL or run
298
JavaScript programs; it is conceptually similar to the `node` shell which ships with Node.js.
0 commit comments