folly::ensureCleanupAfterTask

Composes a task with an async cleanup that always runs after it.

Synopsis

Declared in <folly/futures/Cleanup.h>

template<typename T>
folly::SemiFuture<T>
ensureCleanupAfterTask(
    folly::SemiFuture<T> task,
    folly::SemiFuture<folly::Unit> cleanup);

Description

This helps compose a task with async cleanup The task result is stored until cleanup completes and is then produced The cleanup task is not allowed to fail.

This can be used with collectAll to combine multiple async resources

ensureCleanupAfterTask(collectAll(a.run(), b.run()), collectAll(a.cleanup(), b.cleanup())).wait();

Return Value

A SemiFuture producing the task result after cleanup completes.

Parameters

NameDescription
taskThe task whose result is produced once cleanup completes.
cleanupThe cleanup task run after the task; it must not fail.