diff --git a/folly/experimental/FunctionScheduler.cpp b/folly/experimental/FunctionScheduler.cpp index 6dfb2c2c76f..83fba55b162 100644 --- a/folly/experimental/FunctionScheduler.cpp +++ b/folly/experimental/FunctionScheduler.cpp @@ -445,6 +445,7 @@ void FunctionScheduler::runOneFunction(std::unique_lock& lock, } if (currentFunction_->runOnce) { // Don't reschedule if the function only needed to run once. + currentFunction_ = nullptr; return; } // Clear currentFunction_ diff --git a/folly/experimental/test/FunctionSchedulerTest.cpp b/folly/experimental/test/FunctionSchedulerTest.cpp index d881bfd1461..23293d2c5b2 100644 --- a/folly/experimental/test/FunctionSchedulerTest.cpp +++ b/folly/experimental/test/FunctionSchedulerTest.cpp @@ -456,6 +456,13 @@ TEST(FunctionScheduler, AddWithRunOnce) { EXPECT_EQ(2, total); delay(2); EXPECT_EQ(2, total); + + fs.addFunctionOnce([&] { total += 2; }, "add2"); + delay(1); + EXPECT_EQ(4, total); + delay(2); + EXPECT_EQ(4, total); + fs.shutdown(); }