mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
52a995d611
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
39 lines
687 B
C++
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_;
|
|
};
|