I have a simple POST Grape endpoint with Wisper pub/sub in a background:
module Something
class Doit < Grape::API
post :now do
service = SomePub.new
service.subscribe(SomeSub.new)
service.call(params)
end
end
end
Here is the SomeSub
where actually calculations happens:
class SomeSub
def do_calculations(payload)
{result: "42"}.to_json
end
end
SomePub
is simple too:
class SomePub
include Wisper::Publisher
def call(payload)
broadcast(:do_calculations, payload)
end
end
So what I need is to respond with the JSON {result: "42"}
, when calling the Grape's post :now
endpoint.
Unfortunately it doesn't work this way, and what I have is:
{"local_registrations":[{"listener":{},"on":{},"with":null,"prefix":"","allowed_classes":[],"broadcaster":{}}]}
That example from Wisper's wiki doesn't help too much (https://github.com/krisleech/wisper/wiki/Grape)
Any ideas how to actually pass SomePub#do_calculations
results, as a result of Grape's endpoint call?