MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ with_async() [1/2]

template<ComputeData StartType, typename ChainFunc , typename CompleteFn >
void MayaFlux::Yantra::ComputeMatrix::with_async ( Datum< StartType >  input,
ChainFunc &&  chain,
CompleteFn &&  on_complete 
)
inline

Execute an operation chain asynchronously.

chain receives a FluentExecutor seeded with input and must return the terminal Datum. The entire sequence runs on a background thread. on_complete is invoked with the result on that same thread.

The future is owned by this matrix instance. drain_async() and the destructor guarantee all in-flight chains finish before the matrix is destroyed. No thread management is required by the caller.

matrix->with_async(make_granular_input(container),
[](auto chain) {
return chain.then<SegmentOp>("segment")
.then<AttributeOp>("attribute")
.then<SortOp>("sort")
.to_io();
},
ex->grains = std::move(result);
ex->ready = true;
});
Input/Output container for computation pipeline data flow with structure preservation.
Definition DataIO.hpp:24
Template Parameters
StartTypeInput data type.
ChainFuncCallable: (FluentExecutor<ComputeMatrix, StartType>) -> Datum<ResultType>.
CompleteFnCallable: (Datum<R>) -> void, where R is deduced from ChainFunc.
Parameters
inputSeed datum for the chain.
chainLambda describing the full operation sequence.
on_completeCalled with the final Datum on completion.

Definition at line 401 of file ComputeMatrix.hpp.

402 {
403 auto self = shared_from_this();
404 register_async(std::async(std::launch::async,
405 [self,
406 input = std::move(input),
407 chain = std::forward<ChainFunc>(chain),
408 on_complete = std::forward<CompleteFn>(on_complete)]() mutable {
409 on_complete(chain(
410 FluentExecutor<ComputeMatrix, StartType>(self, std::move(input))));
411 }));
412 }
void register_async(std::future< void > f)
Tendency< A, C > chain(const Tendency< A, B > &first, const Tendency< B, C > &second)
Sequential composition: evaluate first, feed result into second.
Definition Tendency.hpp:82