Skip to content

Commit

Permalink
[jsscripting] Implement NodeJS-like parameter handling for timer poly…
Browse files Browse the repository at this point in the history
…fills (#15193)

* [jsscripting] Implement NodeJS-like param handling for timer polyfills
* [jsscripting] Clean-Up ThreadsafeTimer methods

Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
  • Loading branch information
florian-h05 authored Jul 7, 2023
1 parent 7a8ef1f commit 2d75536
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,6 @@ public Timer createTimer(@Nullable String identifier, ZonedDateTime instant, Run
* <code>clearTimeout()</code> to cancel the timeout.
*/
public long setTimeout(Runnable callback, Long delay) {
return setTimeout(callback, delay, new Object());
}

/**
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/setTimeout"><code>setTimeout()</code></a> polyfill.
* Sets a timer which executes a given function once the timer expires.
*
* @param callback function to run after the given delay
* @param delay time in milliseconds that the timer should wait before the callback is executed
* @param args
* @return Positive integer value which identifies the timer created; this value can be passed to
* <code>clearTimeout()</code> to cancel the timeout.
*/
public long setTimeout(Runnable callback, Long delay, @Nullable Object... args) {
long id = lastId.incrementAndGet();
ScheduledCompletableFuture<Object> future = scheduler.schedule(() -> {
lock.lock();
Expand Down Expand Up @@ -153,20 +139,6 @@ public void clearTimeout(long timeoutId) {
* <code>clearInterval()</code> to cancel the interval.
*/
public long setInterval(Runnable callback, Long delay) {
return setInterval(callback, delay, new Object());
}

/**
* <a href="https://developer.mozilla.org/en-US/docs/Web/API/setInterval"><code>setInterval()</code></a> polyfill.
* Repeatedly calls a function with a fixed time delay between each call.
*
* @param callback function to run
* @param delay time in milliseconds that the timer should delay in between executions of the callback
* @param args
* @return Numeric, non-zero value which identifies the timer created; this value can be passed to
* <code>clearInterval()</code> to cancel the interval.
*/
public long setInterval(Runnable callback, Long delay, @Nullable Object... args) {
long id = lastId.incrementAndGet();
ScheduledCompletableFuture<Object> future = scheduler.schedule(() -> {
lock.lock();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d75536

Please sign in to comment.