Skip to content

Commit d1f2fcb

Browse files
authored
Merge pull request #173 from marcgurevitx/true-os-sleep
True OS sleep on yield() and wait()
2 parents 11d594e + f2b2e42 commit d1f2fcb

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

MiniScript-cpp/src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <iostream>
1010
#include <fstream>
1111
#include <string>
12+
#include <chrono>
13+
#include <thread>
1214
#include "MiniScript/SimpleString.h"
1315
#include "MiniScript/UnicodeUtil.h"
1416
#include "MiniScript/UnitTest.h"
@@ -22,6 +24,9 @@
2224
#include "ShellIntrinsics.h"
2325
#include "DateTimeUtils.h" // TEMP for initial testing
2426

27+
// YIELD_NANOSECONDS: How many nano-seconds to sleep when yielding.
28+
#define YIELD_NANOSECONDS 10000000
29+
2530
using namespace MiniScript;
2631

2732
bool printHeaderInfo = true;
@@ -127,6 +132,7 @@ static int DoCommand(Interpreter &interp, String cmd) {
127132
while (!interp.Done()) {
128133
try {
129134
interp.RunUntilDone();
135+
std::this_thread::sleep_for(std::chrono::nanoseconds(YIELD_NANOSECONDS));
130136
} catch (MiniscriptException& mse) {
131137
std::cerr << "Runtime Exception: " << mse.message << std::endl;
132138
interp.vm->Stop();

0 commit comments

Comments
 (0)