tags: api/syscall references:
The Service API exposes a simple service registry leveraged by various parts of SilverBullet. See Service.
${spacelua.renderApiDocumentation("service")}
Services are built on top of Event|Events. When a service is defined, it registers two event listeners:
discover:<<selector>> for service discoveryservice:<<guid>> for invocationDiscovery broadcasts on the event bus and collects all matches, sorted by priority. Invocation calls the specific service's run callback.
service.define {
selector = "greeter-service",
match = {},
run = function(name)
return "Hello " .. name
end
}
service.define {
selector = "greeter-service",
match = function(name)
if name == "Pete" then
return {priority=10}
else
return nil
end
end,
run = function(name)
return "Hello Pete, so happy to see you!"
end
}
To invoke: ${service.invokeBestMatch("greeter-service", "Pete")} and ${service.invokeBestMatch("greeter-service", "Hank")}