• danakj's avatar
    Add *Callback::Then() to chain 2 callbacks together · fcc5e7c2
    danakj authored
    a.Then(b) will return a new callback that when Run() will
    1) run |a|
    2) run |b|, passing it the return value from a
    3) return the result from |b|
    
    OnceCallbacks must be destroyed when joining them together with Then(),
    so the method is rvalue-qualified. This means it is used in the
    same way as Run(), for example, this function posts two callbacks to
    run together as a single task:
    
    void PostTwoTasks(base::OnceClosure c1, base::OnceClosure c2) {
      PostTask(std::move(c1).Then(std::move(c2)));
    }
    
    RepeatingCallback can be joined destructively via the rvalue-qualified
    overload, or non-destructively otherwise. The latter is allowed for a
    RepeatingCallback because it is meant to have multiple callers and
    therefore having both the original callbacks and the joined callback
    pointing to the same underlying functor is not problematic.
    
    R=chrisha@chromium.org, gab@chromium.org
    
    Bug: 1140582
    Change-Id: Ie147f01d1c8adeb5ed34e4933f211e7d247e3c6b
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485642
    Commit-Queue: danakj <danakj@chromium.org>
    Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
    Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
    Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#820319}
    fcc5e7c2
callback_internal.h 7.36 KB