Skip to content

[FEAT] def_async #2658

@hiaselhans

Description

@hiaselhans

i made a simple Awaitable class in c++ to support pythons async/await syntax with c++ deferred functions:

template<typename ResultType>
class Awaitable : public std::enable_shared_from_this<Awaitable<ResultType>>{
    public:
        Awaitable();
        Awaitable(std::future<ResultType>&);
        std::shared_ptr<Awaitable<ResultType>> __iter__();
        std::shared_ptr<Awaitable<ResultType>> __await__();
        
        void __next__();

    private:
        std::future<ResultType> future;
};

is this something that would have a chance to land in pybind11?
So, supporting an interface like:

m.def_async("name", &function_returning_a_future);

What seems to be missing for this is a StopIteration exception type with templated "return" type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions