Namespaces

Enumerations

enum result_state
Name Value
pending 0
ok 1
error 2

Describes the status of a task's result.

Defined at line 66 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

enum future_state
Name Value
empty 0
pending 1
ok 2
error 3

Describes the status of a future.

Defined at line 999 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

Records

Functions

  • template <class... Tag>
    bridge<Tag...> <deduction guide for bridge> (typename Tag::__allow_ctad... )

    This suppresses the '-Wctad-maybe-unsupported' compiler warning when CTAD is used.

    See https://github.com/llvm/llvm-project/blob/42874f6/libcxx/include/__config#L1259-L1261.

  • pending_result pending ()

    Returns an value that represents a pending result.

    Defined at line 21 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

  • template <typename V>
    ok_result<V> ok (V value)

    Wraps the result of a successful task as an |ok_result

    <T

    >|.

    Defined at line 39 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

  • ok_result<> ok ()

    Defined at line 42 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

  • promise_impl< ::fpromise::internal::result_continuation<usb_xhci::TRB *, zx_status_t>> make_error_promise (zx_status_t error)

    Defined at line 59 of file ../../src/devices/usb/drivers/xhci/xhci-context.h

  • template <typename E>
    error_result<E> error (E error)

    Wraps the result of a failed task as an |error_result

    <T

    >|.

    Defined at line 60 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

  • error_result<> error ()

    Defined at line 63 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

  • promise_impl< ::fpromise::internal::result_continuation<usb_xhci::TRB *, zx_status_t>> make_ok_promise (usb_xhci::TRB * trb)

    Defined at line 64 of file ../../src/devices/usb/drivers/xhci/xhci-context.h

  • template <typename V, typename E>
    void swap (result<V, E> & a, result<V, E> & b)

    Defined at line 235 of file ../../sdk/lib/fit-promise/include/lib/fpromise/result.h

  • template <typename Promise>
    consumer<typename Promise::value_type, typename Promise::error_type> schedule_for_consumer (fpromise::executor * executor, Promise promise)

    Schedules |promise| to run on |executor| and returns a |consumer| which

    receives the result of the promise upon its completion.

    This method has the effect of decoupling the evaluation of a promise from

    the consumption of its result such that they can be performed on different

    executors (possibly on different threads).

    |executor| must be non-null.

    |promise| must be non-empty.

    EXAMPLE

    This example shows an object that encapsulates its own executor which it

    manages independently from that of its clients. This enables the object

    to obtain certain assurances such as a guarantee of single-threaded

    execution for its internal operations even if its clients happen to be

    multi-threaded (or vice-versa as desired).

    // This model has specialized internal threading requirements so it

    // manages its own executor.

    class model {

    public:

    fpromise::consumer

    <int

    > perform_calculation(int parameter) {

    return fpromise::schedule_for_consumer(

    &executor

    _,

    fpromise::make_promise([parameter] {

    // In reality, this would likely be a much more

    // complex expression.

    return fpromise::ok(parameter * parameter);

    });

    }

    private:

    // The model is responsible for initializing and running its own

    // executor (perhaps on its own thread).

    fpromise::single_threaded_executor executor_;

    };

    // Asks the model to perform a calculation, awaits a result on the

    // provided executor (which is different from the one internally used

    // by the model), then prints the result.

    void print_output(fpromise::executor* executor, model* m) {

    executor->schedule_task(

    m->perform_calculation(16)

    .promise_or(fpromise::error())

    .and_then([] (const int

    &

    result) { printf("done: %d\n", result); })

    .or_else([] { puts("failed or abandoned"); }));

    }

    Defined at line 454 of file ../../sdk/lib/fit-promise/include/lib/fpromise/bridge.h

  • template <typename Continuation>
    void swap (promise_impl<Continuation> & a, promise_impl<Continuation> & b)

    Defined at line 775 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Continuation>
    bool operator== (const promise_impl<Continuation> & f, decltype(nullptr) )

    Defined at line 780 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Continuation>
    bool operator== (decltype(nullptr) , const promise_impl<Continuation> & f)

    Defined at line 784 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Continuation>
    bool operator!= (const promise_impl<Continuation> & f, decltype(nullptr) )

    Defined at line 788 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Continuation>
    bool operator!= (decltype(nullptr) , const promise_impl<Continuation> & f)

    Defined at line 792 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename PromiseHandler>
    promise_impl< ::fpromise::internal::promise_continuation<PromiseHandler>> make_promise (PromiseHandler handler)

    Returns an unboxed promise that wraps the specified handler.

    The type of the promise's result is inferred from the handler's result.

    |handler| is a callable object (such as a lambda. Must not be null.

    The handler must return one of the following types:

    - void

    - fpromise::result

    <value

    _type, error_type>

    - fpromise::ok

    <value

    _type>

    - fpromise::error

    <error

    _type>

    - fpromise::pending

    - fpromise::promise

    <value

    _type, error_type>

    - any callable or unboxed promise with the following signature:

    fpromise::result

    <value

    _type, error_type>(fpromise::context

    &

    )

    The handler must accept one of the following argument lists:

    - ()

    - (fpromise::context

    &

    )

    See documentation of |fpromise::promise| for more information.

    SYNOPSIS

    |Handler| is the handler function type. It is typically inferred by the

    compiler from the |handler| argument.

    EXAMPLE

    enum class weather_type { sunny, glorious, cloudy, eerie, ... };

    weather_type look_outside() { ... }

    void wait_for_tomorrow(fpromise::suspended_task task) {

    ... arrange to call task.resume_task() tomorrow ...

    }

    fpromise::promise

    <weather

    _type, std::string> wait_for_good_weather(int max_days) {

    return fpromise::make_promise([days_left = max_days] (fpromise::context

    &

    context) mutable

    -> fpromise::result

    <int

    , std::string> {

    weather_type weather = look_outside();

    if (weather == weather_type::sunny || weather == weather_type::glorious)

    return fpromise::ok(weather);

    if (days_left > 0) {

    wait_for_tomorrow(context.suspend_task());

    return fpromise::pending();

    }

    days_left--;

    return fpromise::error("nothing but grey skies");

    });

    }

    auto f = wait_for_good_weather(7)

    .and_then([] (const weather_type

    &

    weather) { ... })

    .or_else([] (const std::string

    &

    error) { ... });

    Defined at line 865 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Continuation>
    promise_impl<Continuation> make_promise_with_continuation (Continuation continuation)

    Makes a promise containing the specified continuation.

    This function is used for making a promises given a callable object

    that represents a valid continuation type. In contrast,

    |fpromise::make_promise()| supports a wider range of types and should be

    preferred in most situations.

    |Continuation| is a callable object with the signature

    fpromise::result

    <V

    , E>(fpromise::context

    &

    ).

    Defined at line 806 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename V = void, typename E = void>
    promise_impl< ::fpromise::internal::result_continuation<V, E>> make_result_promise (fpromise::result<V, E> result)

    Returns an unboxed promise that immediately returns the specified result when invoked.

    This function is especially useful for returning promises from functions

    that have multiple branches some of which complete synchronously.

    |result| is the result for the promise to return.

    See documentation of |fpromise::promise| for more information.

    Defined at line 884 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename V = void, typename E = void>
    promise_impl< ::fpromise::internal::result_continuation<V, E>> make_result_promise (fpromise::ok_result<V> result)

    Defined at line 890 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename V = void, typename E = void>
    promise_impl< ::fpromise::internal::result_continuation<V, E>> make_result_promise (fpromise::error_result<E> result)

    Defined at line 896 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename V = void, typename E = void>
    promise_impl< ::fpromise::internal::result_continuation<V, E>> make_result_promise (fpromise::pending_result result)

    Defined at line 902 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename V>
    promise_impl< ::fpromise::internal::result_continuation<V, void>> make_ok_promise (V value)

    Returns an unboxed promise that immediately returns the specified value when invoked.

    This function is especially useful for returning promises from functions

    that have multiple branches some of which complete synchronously.

    |value| is the value for the promise to return.

    See documentation of |fpromise::promise| for more information.

    Defined at line 917 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • promise_impl< ::fpromise::internal::result_continuation<void, void>> make_ok_promise ()

    Overload of |make_ok_promise()| used when the value type is void.

    Defined at line 922 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename E>
    promise_impl< ::fpromise::internal::result_continuation<void, E>> make_error_promise (E error)

    Returns an unboxed promise that immediately returns the specified error when invoked.

    This function is especially useful for returning promises from functions

    that have multiple branches some of which complete synchronously.

    |error| is the error for the promise to return.

    See documentation of |fpromise::promise| for more information.

    Defined at line 935 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • promise_impl< ::fpromise::internal::result_continuation<void, void>> make_error_promise ()

    Overload of |make_error_promise()| used when the error type is void.

    Defined at line 941 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename... Promises>
    promise_impl< ::fpromise::internal::join_continuation<Promises...>> join_promises (Promises... promises)

    Jointly evaluates zero or more promises.

    Returns a promise that produces a std::tuple

    <

    > containing the result

    of each promise once they all complete.

    EXAMPLE

    auto get_random_number() {

    return fpromise::make_promise([] { return rand() % 10 });

    }

    auto get_random_product() {

    auto f = get_random_number();

    auto g = get_random_number();

    return fpromise::join_promises(std::move(f), std::move(g))

    .and_then([] (std::tuple

    <fpromise

    ::result

    <int

    >, fpromise::result

    <int

    >>

    &

    results) {

    return fpromise::ok(results.get

    <

    0>.value() + results.get

    <

    1>.value());

    });

    }

    Defined at line 965 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename V, typename E>
    promise_impl< ::fpromise::internal::join_vector_continuation<fpromise::promise<V, E>>> join_promise_vector (std::vector<fpromise::promise<V, E>> promises)

    Jointly evaluates zero or more homogenous promises (same result and error

    type). Returns a promise that produces a std::vector

    <

    > containing the

    result of each promise once they all complete.

    EXAMPLE

    auto get_random_number() {

    return fpromise::make_promise([] { return rand() % 10 });

    }

    auto get_random_product() {

    std::vector

    <fpromise

    ::promise

    <int

    >> promises;

    promises.push_back(get_random_number());

    promises.push_back(get_random_number());

    return fpromise::join_promise_vector(std::move(promises))

    .and_then([] (std::vector

    <fpromise

    ::result

    <int

    >>

    &

    results) {

    return fpromise::ok(results[0].value() + results[1].value());

    });

    }

    Defined at line 992 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Promise>
    void swap (future_impl<Promise> & a, future_impl<Promise> & b)

    Defined at line 1329 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Promise>
    bool operator== (const future_impl<Promise> & f, decltype(nullptr) )

    Defined at line 1334 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Promise>
    bool operator== (decltype(nullptr) , const future_impl<Promise> & f)

    Defined at line 1338 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Promise>
    bool operator!= (const future_impl<Promise> & f, decltype(nullptr) )

    Defined at line 1342 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Promise>
    bool operator!= (decltype(nullptr) , const future_impl<Promise> & f)

    Defined at line 1346 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • template <typename Promise>
    future_impl<Promise> make_future (Promise promise)

    Makes a future containing the specified promise.

    Defined at line 1352 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h

  • void swap (suspended_task & asuspended_task & b)

    Defined at line 1611 of file ../../sdk/lib/fit-promise/include/lib/fpromise/promise.h