Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.52 KB | None | 0 0
  1.    private Object continuation;
  2.  
  3.    public boolean executeWithContinuations()
  4.    {
  5.       try
  6.       {
  7.          this.enterContext();
  8.  
  9.          if (this.continuation == null)
  10.          {
  11.             Context c = this.fetchRhinoContext();
  12.             Scriptable s = this.fetchRhinoScope();
  13.             c.executeScriptWithContinuations(this.rhinoScript, s);
  14.          }
  15.          else
  16.          {
  17.             this.resume();
  18.          }
  19.  
  20.          // done
  21.          return false;
  22.       }
  23.       catch (ContinuationPending pending)
  24.       {
  25.          this.continuation = pending.getContinuation();
  26.  
  27.          // continue later
  28.          return true;
  29.       }
  30.       finally
  31.       {
  32.          this.exitContext();
  33.       }
  34.    }
  35.  
  36.    public void yield()
  37.    {
  38.       if (this.continuation != null)
  39.       {
  40.          throw new IllegalStateException();
  41.       }
  42.  
  43.       try
  44.       {
  45.          this.enterContext();
  46.  
  47.          throw this.fetchRhinoContext().captureContinuation();
  48.       }
  49.       finally
  50.       {
  51.          this.exitContext();
  52.       }
  53.    }
  54.  
  55.    private void resume()
  56.    {
  57.       if (this.continuation == null)
  58.       {
  59.          throw new IllegalStateException();
  60.       }
  61.  
  62.       final Object cont = this.continuation;
  63.  
  64.       this.continuation = null;
  65.  
  66.       try
  67.       {
  68.          this.enterContext();
  69.  
  70.          Context c = this.fetchRhinoContext();
  71.          Scriptable s = this.fetchRhinoScope();
  72.          c.resumeContinuation(cont, s, null);
  73.       }
  74.       finally
  75.       {
  76.          this.exitContext();
  77.       }
  78.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement