Skip to content

Commit 561c2c8

Browse files
committed
Document existence of subscriptions and events API
1 parent 425494c commit 561c2c8

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/main/java/li/cil/oc2/api/README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,24 @@ This can be useful for various things. For example:
7777
- Close and delete the file in `unmount()`.
7878
- Close the file in `suspend()`.
7979

80-
### No Active Back-channel
81-
82-
Unlike some other computer mods (e.g. OpenComputers and ComputerCraft), there is no *active* back-channel in the
83-
`RPCDevice` API. In other words, it is not possible for `RPCDevices` to raise events in the virtual machines. The only
84-
way to provide data to the virtual machines is as values returned from exposed methods. Programs running in the virtual
85-
machines will always have to poll for changed data.
80+
### Subscriptions and Events
81+
82+
The `RPCDevice` API also lets devices raise events in the virtual machine, by implementing the `RPCEventSource`
83+
interface, either on the same class implementing `RPCDevice` or on the one wrapped by `ObjectDevice`. The VM will then
84+
be able to subscribe to events from the device, which can be sent by calling `postEvent` on the `IEventSink` passed
85+
to `subscribe`. An example of this is the built-in `RedstoneInterfaceBlockEntity` device.
86+
87+
#### Note: This is mostly a new feature and there are several caveats to keep in mind when using it.
88+
89+
- If subscriptions are used on or before OC2R version 2.2.12, they can cause a server crash if too many messages are
90+
sent at once. To be safe, do not send any event in the same tick as another message, or depend on a later minimum
91+
version of OC2R.
92+
- Right now, if a lot of messages are sent and the VM does not listen for them, some may be dropped, and there is no
93+
indication to the device or VM when this happens. You cannot depend on the events being reliably delivered, and must
94+
use some other communication channel if reliability is a requirement.
95+
- The on-the-"wire" event and subscription format is probably stable, but the VM's userspace python and lua libraries do
96+
not easily support them yet, and often silently discard events when expecting a different sort of message. Better
97+
support is actively being worked on.
8698

8799
## The `BlockDeviceProvider` and `ItemDeviceProvider`
88100

0 commit comments

Comments
 (0)