!7 p-experiment { catchHibernationException(r { callHibernatable(f serveLater, fg(f print, f reversedString)); }); catchHibernationException(r { callHibernatable(f serveNow, fg(f print, f reversedString)); }); } svoid catchHibernationException(Runnable r) { try { callF(r); } catch (RuntimeException e) { Throwable e2 = innerException(e); if (!e2 instanceof HibernatingTheThread) throw rethrow(e); } } sclass HibernationFuture { new Flag done; O value; Runnable continuation; void setContinuation(Runnable r) { synchronized(done) { if (!done.isUp()) ret with continuation = r; } callF(r); } void setValue(O value) { synchronized(done) { if (done.isUp()) fail("setValue called twice"); this.value = value; done.raise(); } callF(continuation); } O getValue() { assertTrue(done.isUp()); ret value; } } // f1: func -> A, f2 : func(A) -> B, returns: B static O callHibernatable(O f1, fO f2) { O result; try { result = callF(f1); } catch (RuntimeException e) { Throwable e2 = innerException(e); if (!e2 instanceof HibernatingTheThread) throw rethrow(e); final HibernationFuture f = e2/HibernatingTheThread.future; final new HibernationFuture future2; f.setContinuation(r { future2.setValue(callF(f2, f.getValue())) }); throw HibernatingTheThread(future2); } ret callF(f2, result); } sS serveNow() { ret "Served now"; } sS serveLater() { final new HibernationFuture f; doLater(1000, r { f.setValue("Served late") }); throw HibernatingTheThread(f); } sclass HibernatingTheThread extends QuickException { HibernationFuture future; *(HibernationFuture *future) {} }