Files
react-native/ReactCommon/react/renderer/runtimescheduler/tests/StubQueue.h
T
Samuel Susla 52a995d611 Add yielding mechanism to RuntimeScheduler
Summary:
Changelog: [internal]

Add yielding mechanism to RuntimeScheduler. It is disabled unless `RuntimeScheduler::setEnableYielding` is called.

Reviewed By: JoshuaGross

Differential Revision: D28024376

fbshipit-source-id: 12a7d09d201962e10cadcb352df4967657345d36
2021-05-13 08:03:29 -07:00

39 lines
687 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <queue>
class StubQueue {
public:
void runOnQueue(std::function<void()> &&func) {
callbackQueue_.push(func);
}
void flush() {
while (!callbackQueue_.empty()) {
tick();
}
}
void tick() {
if (!callbackQueue_.empty()) {
auto callback = callbackQueue_.front();
callback();
callbackQueue_.pop();
}
}
int size() {
return callbackQueue_.size();
}
private:
std::queue<std::function<void()>> callbackQueue_;
};