ruby - Javascript event loop/message pump for Google Sketchup plugin -
i'm working on plugin google sketchup written using ruby api. within api webdialog class 1 can use render html , move data between webdialog , ruby side of plugin code. i'm using class build ui plugin.
data sent webdialog ruby side asynchronously. due subpar documentation not aware of , i'm ways plugin it's began create problems me. specifically: when multiple successive calls made webdialog ruby side, last call executed. so, need devise sort of "bridge" prevent calls webdialog ruby side getting lost -- is, think, "event loop" or "message pump" system.
my problem haven't idea of how this. i'm hoping can provide me sort of resource lays out framework how such system should work -- sort of checks needed, sequence in they're performed, etc. know can terrifically complex task, need basic: basically, way of making javascript stop when send request ruby, not proceeding until data need back, , dealing potential errors may crop up.
any appreciated!
i've spent great deal of time webdialog class. planned write such pump, found differently more reliable results.
( webdialog findings: http://forums.sketchucation.com/viewtopic.php?f=180&t=23445 )
alternative method
sketchup > javascript
my alternative method didn't try push data webdialog ruby. instead had ruby pump webdialog because webdialog.execute_script synchronous.
i send command webdialog query. javascript processes , put result hidden input element use ´webdialog.get_element_value` fetch content of.
all of wrapped wrapper method process return value , convert appropriate ruby objects. http://www.thomthom.net/software/sketchup/tt_lib2/doc/tt/gui/window.html#call_script-instance_method
the outline is:
- make call ( .execute_script ) clear hidden input element
- make actual call js process , put return value hidden input
- use .get_element_value fetch hidden input value
all synchronous.
javascript pump
javascript > sketchup
if need pump information js, think need this:
- js: push messages message queue
- js: send message su there messages
- su: when callback notifies new messages, query js next message , continue until there no more messages. should work it'd similar method described earlier.
the concept store messages , hand on control sketchup side can pump synchronously.
(untested theory.)
Comments
Post a Comment