- public static void sleep(int i) {
- java.lang.Thread thread = java.lang.Thread.currentThread();
- if (!(thread instanceof ThreadMessage)) {
- if (Log.on) Log.log(XWT.class, "cannot sleep() or yield() in the foreground thread");
- } else {
- ThreadMessage mythread = (ThreadMessage)thread;
- mythread.done.release();
- if (i > 0) try { java.lang.Thread.sleep(i); } catch (Exception e) { }
- Message.Q.add(mythread);
- mythread.go.block();
- }
+ public static void sleep(final int i) {
+ final JS.Thread jsthread = JS.Thread.current();
+ final long currentTime = System.currentTimeMillis();
+ final Scheduler.Task task = new Scheduler.Task() { public Object call(Object arg) {
+ if (System.currentTimeMillis() - currentTime < i) {
+ Scheduler.add(this);
+ } else {
+ jsthread.resume();
+ }
+ return null;
+ } };
+ jsthread.pause();
+ Scheduler.add(task);