Namespaces

Functions

  • template <typename FidlMethod>
    auto as_promise (::fidl::internal::NaturalThenable<FidlMethod> && thenable)

    |as_promise| converts a FIDL asynchronous call in the new C++ bindings

    into a promise. Example usage:

    // Let's say an async FIDL call originally uses a callback.

    fidl::Client

    <MyProtocol

    > client(...);

    client->Foo({ ... }).Then([] (fidl::Result

    <MyProtocol

    ::Foo>

    &

    result) {

    assert(result.is_ok());

    });

    // It can be turned into a promise by wrapping the call with |as_promise|

    // as opposed to attaching a callback via |Then|:

    auto p1 = fidl_fpromise::as_promise(client->Foo({ ... }));

    // And used like any other regular promise:

    auto p2 = p1.then([] (auto

    &

    result) {

    assert(result.is_ok());

    });

    some_executor.schedule_task(std::move(p2));

    The signature of the resulting promise is akin to

    fpromise::promise

    <SuccessType

    , ErrorType>

    where |SuccessType| is the payload type for when the FIDL call succeeds, or

    |void| if the FIDL call has an empty/zero-argument payload.

    where |ErrorType| is |fidl::Error| if the FIDL call does not use application

    errors, and |fidl::ErrorsIn

    <MyProtocol

    ::FidlMethod>| otherwise. |MyProtocol|

    and |FidlMethod| are all placeholders to be replaced by the actual protocol

    and method names.

    Defined at line 59 of file ../../src/lib/fidl/contrib/fpromise/client.h