Sorry for the slow response.
Have been playing around with services, have a couple of questions.
* Why the need for bp_require? It looks like it needs an absolute path from the service folder too.
* Is bp.complete part of the async api. If so, that's really cool! This async api makes it really easy to add bonjour integration. Can I call it multiple times?
* Can I return Ruby objects?
I'm thinking a Bonjour api would look like this:
PlusJour.list(service_name, timeout=3)
PlusJour.register(service_name, name, port, text_record)
This sort of thing is currently really hard to test with the current workflow (especially since it deletes your code if you get anything wrong!), but I'm sure that'll change with the published api.
Can you PM me if there's some sort of private beta for that api.
Thanks,
Alex
Hey Alex,
require() will use relative paths from the rubystdlib installed. bp_require() will include relative to your service directory (where it's installed).
bp.complete is an async api. Once it's invoked the "transaction" is complete, so it may not be invoked multiple times.
but, you can take "callbacks" as arguments which can be invoked any number of times, here's a sample service that demonstrated:
CODE
class HelloRuby
def initialize(args)
log("init called with #{args.pretty_inspect}")
end
def log(str)
if false
File.open("/tmp/dbg.txt", "a") { |f| f.puts(str) }
end
end
def howdy(bp, args)
Thread.new(bp, args['callback']) do |bp,callback |
(0..10).each do |x|
str = "howdy there, for the #{x}th time"
log(str)
callback.invoke(str)
sleep 0.4
end
bp.complete("Hello world from my great corelet instance!")
end
end
end
rubyCoreletDefinition = {
'class' => "HelloRuby",
'name' => "HelloRuby",
'major_version' => 0,
'minor_version' => 0,
'micro_version' => 7,
'documentation' => 'A service that tests callbacks from ruby.',
'functions' =>
[
{
'name' => 'howdy',
'documentation' => "Say \"hello\" to the world",
'arguments' =>
[
{
'name' => 'callback',
'type' => 'callback',
'required' => true,
'documentation' => 'the callback to send a hello message to'
}
]
}
]
}
short on time, more later,
lloyd