Skip to content

Commit f2b2e42

Browse files
committed
Revert wait() to busy
1 parent 8d29366 commit f2b2e42

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

MiniScript-cpp/src/MiniScript/MiniscriptIntrinsics.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include <cmath>
1515
#include <ctime>
1616
#include <algorithm>
17-
#include <chrono>
18-
#include <thread>
1917

2018
namespace MiniScript {
2119

@@ -857,10 +855,16 @@ namespace MiniScript {
857855
}
858856

859857
static IntrinsicResult intrinsic_wait(Context *context, IntrinsicResult partialResult) {
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;
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+
}
864868
}
865869

866870
static IntrinsicResult intrinsic_yield(Context *context, IntrinsicResult partialResult) {

0 commit comments

Comments
 (0)