Hi all,
Building on the thread here:
http://groups.google.com/group/openwferu-users/browse_thread/thread/88d64384a3015aa7
... our users need to interact with stored workitems, which begs a
question I've seen posted on this list before: how to force Ruote to
behave synchronously, so that users can see their changes to the
system immediately (in our case, they'd otherwise have to reload a web
page).
I refactored John's example, and came up with the following:
----8<----
class PatientParticipant < Ruote::StorageParticipant
class NestedWaitForError < StandardError; end
cattr_accessor :waiting
class << self
def wait_for signal=:next, &block
raise NestedWaitForError, "nesting wait_for is not currently
supported" if self.waiting
begin
self.waiting = [Thread.current, signal]
block.call
Thread.stop if waiting
Thread.current['__patience_result__']
ensure
self.waiting = nil
end
end
def continue workitem
return unless waiting
thread, waiting_for = *waiting
signals = [:next, workitem.participant_name]
if signals.include? waiting_for
thread['__patience_result__'] = workitem
thread.wakeup
end
end
end
def consume workitem
super workitem
self.class.continue workitem.dup
end
end
---->8----
My controller might look like this:
----8<----
FooController < ApplicationController
def update
PatientParticipant.wait_for :next do # "participant_x" works too
# reply to the engine with #params
end
end
end
---->8----
The *only* place I'd use this is where we reply to the engine on
behalf of a user, since I vastly prefer to embrace Ruote's
asynchronous model.
Hope that helps someone.