File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed
Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change 1414#include < cmath>
1515#include < ctime>
1616#include < algorithm>
17+ #include < chrono>
18+ #include < thread>
1719
1820namespace MiniScript {
1921
@@ -855,16 +857,10 @@ namespace MiniScript {
855857 }
856858
857859 static IntrinsicResult intrinsic_wait (Context *context, IntrinsicResult partialResult) {
858- double now = context->vm ->RunTime ();
859- if (partialResult.Done ()) {
860- // Just starting our wait; calculate end time and return as partial result
861- double interval = context->GetVar (" seconds" ).DoubleValue ();
862- return IntrinsicResult (Value (now + interval), false );
863- } else {
864- // Continue until current time exceeds the time in the partial result
865- if (now > partialResult.Result ().DoubleValue ()) return IntrinsicResult::Null;
866- return partialResult;
867- }
860+ double seconds = context->GetVar (" seconds" ).DoubleValue ();
861+ long nanoseconds = seconds * 1000000000 ;
862+ std::this_thread::sleep_for (std::chrono::nanoseconds (nanoseconds));
863+ return IntrinsicResult::Null;
868864 }
869865
870866 static IntrinsicResult intrinsic_yield (Context *context, IntrinsicResult partialResult) {
Original file line number Diff line number Diff line change 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"
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+
2530using namespace MiniScript ;
2631
2732bool 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 ();
You can’t perform that action at this time.
0 commit comments