Skip to content

Instantly share code, notes, and snippets.

View at15four2020's full-sized avatar
๐Ÿ“†
The time is going

Fifteen Four at15four2020

๐Ÿ“†
The time is going
View GitHub Profile
@josmardias
josmardias / setTimeout-nashorn.js
Last active December 10, 2024 21:37 — forked from salomvary/settimeout-nashorn.js
setTimeout polyfill for Nashorn
// https://gist.github.com/josmardias/20493bd205e24e31c0a406472330515a
// at least one timeout needs to be set, larger then your code bootstrap
// or Nashorn will run forever
// preferably, put a timeout 0 after your code bootstrap
(function(context) {
'use strict';
var Timer = Java.type('java.util.Timer');
var Phaser = Java.type('java.util.concurrent.Phaser');
@bripkens
bripkens / event-loop-nashorn.js
Last active August 21, 2021 06:18
Java 8 Nashorn event loop "polyfill". javax.script.ScriptEngine#eval calls should immediately call window.main to enter the event loop and thus to avoid concurrency issues. The XMLHttpRequest simulation is not yet finished.
(function(context) {
'use strict';
var Timer = Java.type('java.util.Timer');
var Phaser = Java.type('java.util.concurrent.Phaser');
var TimeUnit = Java.type('java.util.concurrent.TimeUnit');
var AsyncHttpClient = Java.type('com.ning.http.client.AsyncHttpClient');
var timer = new Timer('jsEventLoop', false);
var phaser = new Phaser();