Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Object continuation;
- public boolean executeWithContinuations()
- {
- try
- {
- this.enterContext();
- if (this.continuation == null)
- {
- Context c = this.fetchRhinoContext();
- Scriptable s = this.fetchRhinoScope();
- c.executeScriptWithContinuations(this.rhinoScript, s);
- }
- else
- {
- this.resume();
- }
- // done
- return false;
- }
- catch (ContinuationPending pending)
- {
- this.continuation = pending.getContinuation();
- // continue later
- return true;
- }
- finally
- {
- this.exitContext();
- }
- }
- public void yield()
- {
- if (this.continuation != null)
- {
- throw new IllegalStateException();
- }
- try
- {
- this.enterContext();
- throw this.fetchRhinoContext().captureContinuation();
- }
- finally
- {
- this.exitContext();
- }
- }
- private void resume()
- {
- if (this.continuation == null)
- {
- throw new IllegalStateException();
- }
- final Object cont = this.continuation;
- this.continuation = null;
- try
- {
- this.enterContext();
- Context c = this.fetchRhinoContext();
- Scriptable s = this.fetchRhinoScope();
- c.resumeContinuation(cont, s, null);
- }
- finally
- {
- this.exitContext();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement