Skip to content

Commit 022893f

Browse files
committed
fix: fix setInterval not repeating correctly
1 parent 119470f commit 022893f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

NativeScript/runtime/Timers.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ void Timers::SetTimer(const v8::FunctionCallbackInfo<v8::Value>& args, bool repe
210210
}
211211

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

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

226-
227-
auto timeoutInSeconds = timeout / 1000.f;
227+
// timeout should be bigger than 0 if it's repeatable and 0
228+
auto timeoutInSeconds = repeatable && timeout == 0 ? 0.0000001f : timeout / 1000.f;
228229
auto timer = CFRunLoopTimerCreate(kCFAllocatorDefault,
229230
CFAbsoluteTimeGetCurrent() + timeoutInSeconds,
230231
repeatable ? timeoutInSeconds : 0,

0 commit comments

Comments
 (0)