Go: Cross-mod: bus, services and lanes¶
Functions¶
BusSubscribe¶
| Go | |
|---|---|
BusSubscribe calls fn for every message published on topic, on the publisher's thread, whichever language the publisher is written in. fn returns a veto: true refuses a vetoable publish and false has no opinion, and a plain publish ignores it. A subscriber can only refuse, never overturn another's refusal. Namespace topics, as "plot:enter".
- Parameters:
- topic :
string - fn :
func(topic, payload string) (veto bool)
- topic :
- Return type:
(*Subscription, error) - Slots:
bus_subscribe
BusPublish¶
| Go | |
|---|---|
BusPublish sends payload to every subscriber of topic and returns how many ran; 0 is a normal answer, meaning nobody is listening. The payload is opaque to the host, so the two mods agree on its format, JSON or SNBT, out of band.
- Parameters:
- topic :
string - payload :
string
- topic :
- Return type:
(uint32, error) - Slots:
bus_publish
BusPublishVetoable¶
| Go | |
|---|---|
BusPublishVetoable sends payload and collects the subscribers' vetoes.
- Parameters:
- topic :
string - payload :
string
- topic :
- Return type:
(Vetoable, error) - Slots:
bus_publish_vetoable
BusSubscriberCount¶
| Go | |
|---|---|
BusSubscriberCount is how many subscribers topic has now.
- Parameters:
- topic :
string
- topic :
- Return type:
(uint32, error) - Slots:
bus_subscriber_count
RegisterService¶
| Go | |
|---|---|
RegisterService answers calls to name from mods of any language, and from native plugins through the bridge. fn receives the request and returns the reply, or an error whose message reaches the caller unchanged. It runs on the caller's thread, and also while this mod is disabled but loaded, since consumers resolve services in their own on_load.
- Parameters:
- name :
string - fn :
func(request string) (string, error)
- name :
- Return type:
(*ServiceRegistration, error) - Slots:
service_register
CallService¶
| Go | |
|---|---|
CallService calls another mod's service, whatever language it is written in, and returns its reply or a *CallError.
- Parameters:
- name :
string - request :
string
- name :
- Return type:
(string, error) - Slots:
service_call
CallServiceOptional¶
| Go | |
|---|---|
CallServiceOptional is CallService with nobody providing the name as found false, for an optional integration that works without the other mod.
- Parameters:
- name :
string - request :
string
- name :
- Return type:
(reply string, found bool, err error) - Slots:
service_call
ListServices¶
| Go | |
|---|---|
ListServices lists every registered service.
- Return type:
([]ServiceInfo, error) - Slots:
service_list
ServiceExists¶
| Go | |
|---|---|
ServiceExists reports whether some mod provides name now.
- Parameters:
- name :
string
- name :
- Return type:
bool - Slots:
service_list
ServiceCaller¶
| Go | |
|---|---|
ServiceCaller is the mod whose call is running, asked inside a provider. It is false outside a provider and for a caller with no mod, such as a native plugin through the bridge: a provider then knows it cannot attribute the request.
- Return type:
(string, bool) - Slots:
service_caller
Subscription¶
Subscription is one bus subscription, kept to end it.
Subscription.ID¶
| Go | |
|---|---|
ID is the host's id of the subscription.
- Return type:
uint64
Subscription.Topic¶
| Go | |
|---|---|
Topic is the topic subscribed to.
- Return type:
string
Subscription.Unsubscribe¶
| Go | |
|---|---|
Unsubscribe ends the subscription. Calling it twice is harmless.
- Return type:
error - Slots:
bus_unsubscribe
ServiceRegistration¶
ServiceRegistration is one service this mod provides, kept to withdraw it.
ServiceRegistration.ID¶
| Go | |
|---|---|
ID is the host's id of the registration.
- Return type:
uint64
ServiceRegistration.Name¶
| Go | |
|---|---|
Name is the service name.
- Return type:
string
ServiceRegistration.Unregister¶
| Go | |
|---|---|
Unregister withdraws the service. Calling it twice is harmless.
- Return type:
error - Slots:
service_unregister
CallError¶
CallError is why a service call failed: nobody provides the name, the provider said no and Message is what it said, the host refused the call (a bad name, a call to itself or a cycle), or the host has no service capability.
CallError.Error¶
| Go | |
|---|---|
- Return type:
string
Vetoable¶
| Go | |
|---|---|
Vetoable is the result of one vetoable publish.
CallErrorKind¶
| Go | |
|---|---|
CallErrorKind says why a service call failed.
| Name | Value | Description |
|---|---|---|
CallNotFound |
1 |
|
CallProvider |
2 |
|
CallRefused |
3 |
|
CallUnavailable |
4 |
ServiceInfo¶
ServiceInfo is one registered service and the mod providing it.