On Jan 9, 1:51 am, Terry Braun <[email protected]> wrote: > I've looked up how to synchronize a function in javascript with rhino, > but I'm wondering if there is a way to synchronize on an object instead. > I have lots of object that one method uses, and I don't care how many > threads operate as long as they are not working on the same object ( a > memory stream). > > The example I found was this kind of thing: > > function send(stream) { stuff ... } > var o = {fsend: sync(send) }; > o.fsend(stream); > > but what i want is: > > function send(stream) { > sync(stream); > stuff .... > > } > > Is there a javascript way to that? I may have missed something or ....
sync will lock the functions `this` for the duration of the function. So write the send function as a sync()-ed function _inside_ the stream object. alternatively, do this: ``` var syncSend = sync(send); syncSend.call(stream, stream); ``` making the stream both the `this` object to sync, and the argument to the function ... (small warning: I am no expert and this is totally untested) regards, -Onne > Thanks > Terry _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
