Activities: Add force wakeup API (#27336)

* Activities: Add force wakeup API

* Automated change: Fix sanity tests

Co-authored-by: ctiller <ctiller@users.noreply.github.com>
reviewable/pr27347/r1
Craig Tiller 4 years ago committed by GitHub
parent 29948df4ba
commit ac9e52181b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/core/lib/promise/activity.h
  2. 21
      test/core/promise/activity_test.cc

@ -113,6 +113,13 @@ class Activity : private Wakeable {
// Fetch the size of the implementation of this activity.
virtual size_t Size() = 0;
// Force wakeup from the outside.
// This should be rarely needed, and usages should be accompanied with a note
// on why it's not possible to wakeup with a Waker object.
// Nevertheless, it's sometimes useful for integrations with Activity to force
// an Activity to repoll.
void ForceWakeup() { MakeOwningWaker().Wakeup(); }
// Wakeup the current threads activity - will force a subsequent poll after
// the one that's running.
static void WakeupCurrent() { current()->got_wakeup_during_run_ = true; }

@ -231,6 +231,27 @@ TYPED_TEST(BarrierTest, WakeAfterDestruction) {
b.Clear();
}
TEST(ActivityTest, ForceWakeup) {
StrictMock<MockFunction<void(absl::Status)>> on_done;
int run_count = 0;
auto activity = MakeActivity(
[&run_count]() -> Poll<absl::Status> {
++run_count;
switch (run_count) {
case 1:
return Pending{};
case 2:
return absl::OkStatus();
default:
abort();
}
},
NoCallbackScheduler(),
[&on_done](absl::Status status) { on_done.Call(std::move(status)); });
EXPECT_CALL(on_done, Call(absl::OkStatus()));
activity->ForceWakeup();
}
struct TestContext {
bool* done;
};

Loading…
Cancel
Save