Skip to content

Asyncio Python API - Request For Comment #3

Open
@heri16

Description

@heri16

Would like to add asyncio support to bun_python.

Before I submit the PR, would like to get some thoughts on which API is preferable:

Option A:

import { python, asyncio } from 'bun_python'

const {
    say_hello,
} = python.runModule(await Bun.file(path.resolve(import.meta.dir, 'example.py')).text(), 'example.py')

python.run_loop() // returns a promise that resolves when the loop stops

await asyncio(say_hello('world'), timeout_ms)

main().finally(() => python.stop_loop())

Option A has an asyncio() function to wrap Py Coroutines or Py asyncio.Task into an awaitable JS Promise.

Option B:

import { python } from 'bun_python'

const {
    say_hello,
} = python.runModule(await Bun.file(path.resolve(import.meta.dir, 'example.py')).text(), 'example.py')

python.run_loop()  // returns a promise that resolves when the loop stops

await say_hello('world')

main().finally(() => python.stop_loop())

Option B adds a then() method to all PyObject proxy to make them awaitable.

@codehz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions