Skip to content

Commit

Permalink
fix: fix setInterval not repeating correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
edusperoni committed Jul 28, 2023
1 parent 119470f commit 022893f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions NativeScript/runtime/Timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ void Timers::SetTimer(const v8::FunctionCallbackInfo<v8::Value>& args, bool repe
}

auto task = std::make_shared<TimerTask>(isolate, handler, timeout, repeatable, argArray, id, now_ms());
task->repeats_ = repeatable;

CFRunLoopTimerContext timerContext = {0, NULL, NULL, NULL, NULL};
auto timerData = new TimerContext();
Expand All @@ -223,8 +224,8 @@ void Timers::SetTimer(const v8::FunctionCallbackInfo<v8::Value>& args, bool repe
// so if by our manual release the retain is 0 then we need to cleanup the TimerContext
TimerContext::TimerRetain(timerData);


auto timeoutInSeconds = timeout / 1000.f;
// timeout should be bigger than 0 if it's repeatable and 0
auto timeoutInSeconds = repeatable && timeout == 0 ? 0.0000001f : timeout / 1000.f;
auto timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
CFAbsoluteTimeGetCurrent() + timeoutInSeconds,
repeatable ? timeoutInSeconds : 0,
Expand Down

0 comments on commit 022893f

Please sign in to comment.