Migrate to absl::AnyInvocable

PiperOrigin-RevId: 501392167
This commit is contained in:
Janusz Sobczak
2023-01-11 15:19:33 -08:00
committed by Copybara-Service
parent 3be5844fc3
commit 4fc1583b94
17 changed files with 52 additions and 52 deletions
@@ -48,9 +48,8 @@ using MultiThreadExecutor = ::nearby::api::SubmittableExecutor;
// Execute two runnables that increment the counter.
const int kIncrements = 13;
Runnable incrementer = [self]() { self.counter++; };
for (int i = 0; i < kIncrements; i++) {
executor->Execute(std::move(incrementer));
executor->Execute([self]() { self.counter++; });
[NSThread sleepForTimeInterval:0.01];
}
@@ -64,9 +63,8 @@ using MultiThreadExecutor = ::nearby::api::SubmittableExecutor;
// Submit two runnables that increment the counter.
const int kIncrements = 13;
Runnable incrementer = [self]() { self.counter++; };
for (int i = 0; i < kIncrements; i++) {
executor->DoSubmit(std::move(incrementer));
executor->DoSubmit([self]() { self.counter++; });
[NSThread sleepForTimeInterval:0.01];
}
@@ -46,8 +46,6 @@ using ::nearby::api::ScheduledExecutor;
XCTestExpectation *expectation = [self expectationWithDescription:@"finished"];
Runnable incrementer = [self]() { self.counter++; };
void (^checkCounter)(int, NSTimeInterval, dispatch_block_t) =
^(int expectedCount, NSTimeInterval delay, dispatch_block_t finalBlock) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC)),
@@ -58,13 +56,19 @@ using ::nearby::api::ScheduledExecutor;
};
// Schedule two runnables that increment the counter, at 0.4 and 0.8 seconds.
executor->Schedule(std::move(incrementer), absl::Seconds(0.4));
executor->Schedule(std::move(incrementer), absl::Seconds(0.8));
executor->Schedule([self]() { self.counter++; }, absl::Seconds(0.4));
executor->Schedule([self]() { self.counter++; }, absl::Seconds(0.8));
// Check that the counter contains the expected values at 0.2, 0.6, and 1.0 seconds.
checkCounter(0, 0.2, ^{});
checkCounter(1, 0.6, ^{});
checkCounter(2, 1.0, ^{ [expectation fulfill]; });
checkCounter(0, 0.2,
^{
});
checkCounter(1, 0.6,
^{
});
checkCounter(2, 1.0, ^{
[expectation fulfill];
});
[self waitForExpectationsWithTimeout:1.2 handler:nil];
}
@@ -45,11 +45,9 @@ using SingleThreadExecutor = ::nearby::api::SubmittableExecutor;
- (void)testRunnables {
std::unique_ptr<SingleThreadExecutor> executor([self executor]);
Runnable incrementer = [self]() { self.counter++; };
// Schedule two runnables that increment the counter.
executor->Execute(std::move(incrementer));
executor->Execute(std::move(incrementer));
executor->Execute([self]() { self.counter++; });
executor->Execute([self]() { self.counter++; });
// Check that the counter has the expected value after a moment.
[NSThread sleepForTimeInterval:0.01];