executors / futures

A proposal for a futures programming model for ISO C++
22 stars 7 forks source link

Examples of different future archetypes #9

Open brycelelbach opened 6 years ago

brycelelbach commented 6 years ago
ccmysen commented 6 years ago

Can you explain the differences between these?

jaredhoberock commented 6 years ago

Another I am interested in:

LeeHowes commented 6 years ago

A two-way inline_executor that depends on a ready future could return a ready future. Otherwise I suspect it could not because it would have to know if the input future had completed yet. Having the type there would offer an interesting guarantee in the type system.

RedBeard0531 commented 6 years ago

Related to always_ready_future<T> is always_ready_error_future. I've been toying around with the idea of creating one. It is interesting because it should probably be convertible to future<T> with any T, similar to unexpected<E> for expected<T, E> for any T.

dhollman commented 6 years ago

What about:

(I know this sounds incredibly specific, but I feel like a lot of the discussions on some of the other issue threads, e.g. #5 , boil down to some variant of this)

LeeHowes commented 6 years ago

Supported by in what sense?

The goal of my design sketch was that: 1) Setting callbacks is always safe from a weak agent. 2) Calling non-blocking execute or then_execute is similarly always safe (blocking is blocking, clearly, on some executors blocking might also be safe from a weak agent like a fiber) 3) future.wait() is safe on a weak agent only if the future resulted from a then_executor that is aware of the agent.

With that model you can always call .via(myexec).wait() safely from a weak agent that allows some level of blocking (like a fiber) and at least .execute(callback that satisfies something useful) otherwise.

RedBeard0531 commented 6 years ago

Placeholder comment for "non-thread safe/single threaded shared-state futures". Example implementation adds callbacks to a thread-local work queue when runnable. This is the normal future type used in the nim programing language.