Hi Chris.

On 26/07/2010 5:32 AM, Chris Leavoy wrote:
Could someone please provide me an example of how to create a synchronized
function? The docs provide this:
js>  function test(x) {
   print("entry");
   java.lang.Thread.sleep(x*1000);
   print("exit");
}
js>  var o = { f : sync(test) };
js>  spawn(function() {o.f(5);});
Thread[Thread-0,5,main]
entry
js>  spawn(function() {o.f(5);});

However, the sync(test) line gives me an exception:
org.mozilla.javascript.EcmaError: ReferenceError: "sync" is not defined.

The sync function is only provided in the Rhino shell, so if you're trying to use it in your own embedding of Rhino then it won't work. You can write it yourself easily, though:

  function sync(f) {
    return new Packages.org.mozilla.javascript.Synchronizer(f);
  }

I also use this function:

  function synchronize(on, f) {
    return new Packages.org.mozilla.javascript.Synchronizer(f).call(on);
  }

to immediately run a bit of code synchronized on a given object.
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino

Reply via email to