Module: MTProto::Client::UpdateApi
- Included in:
- MTProto::Client
- Defined in:
- lib/mtproto/client/update_api.rb
Overview
The high-level update-consumption surface of a Client, mixed into it: register update callbacks (with a supported replace/clear seam instead of reaching into the callback list), the post-reconnect hook, and run_updates — the normalized, ordered, exactly-once event stream. The low-level fan-out (dispatch_update) and the @on_update_callbacks / @on_reconnect state stay in Client.
Instance Method Summary collapse
- #clear_update_callbacks ⇒ Object
-
#on_reconnect(&block) ⇒ Object
Register a callback fired after the transport reconnects (a known gap point).
- #on_update(&block) ⇒ Object
-
#replace_update_callback(&block) ⇒ Object
Replace every registered update callback with a single one, so a re-registration never stacks handlers (run_updates relies on this).
-
#run_updates(store:, logger: nil, on_start: nil) ⇒ Object
High-level update consumption: hand the block a normalized, ordered, de-duplicated stream of Updates::Event, with the account and per-channel positions read/written through
store(see Updates::MemoryStore for the contract).
Instance Method Details
#clear_update_callbacks ⇒ Object
23 24 25 |
# File 'lib/mtproto/client/update_api.rb', line 23 def clear_update_callbacks @on_update_callbacks = [] end |
#on_reconnect(&block) ⇒ Object
Register a callback fired after the transport reconnects (a known gap point). It runs on the receiver fiber, so it must NOT block — enqueue work instead.
29 30 31 |
# File 'lib/mtproto/client/update_api.rb', line 29 def on_reconnect(&block) @on_reconnect = block end |
#on_update(&block) ⇒ Object
13 14 15 |
# File 'lib/mtproto/client/update_api.rb', line 13 def on_update(&block) @on_update_callbacks << block end |
#replace_update_callback(&block) ⇒ Object
Replace every registered update callback with a single one, so a re-registration never stacks handlers (run_updates relies on this).
19 20 21 |
# File 'lib/mtproto/client/update_api.rb', line 19 def replace_update_callback(&block) @on_update_callbacks = [block] end |
#run_updates(store:, logger: nil, on_start: nil) ⇒ Object
High-level update consumption: hand the block a normalized, ordered,
de-duplicated stream of Updates::Event, with the account and per-channel
positions read/written through store (see Updates::MemoryStore for the
contract). on_start, if given, runs once inside the started mainloop before
the first update is consumed — where host startup that needs the API belongs,
since an API call raises until the mainloop is running. Blocks until the client
shuts down; Updates::Runner owns the wiring.
40 41 42 |
# File 'lib/mtproto/client/update_api.rb', line 40 def run_updates(store:, logger: nil, on_start: nil, &) Updates::Runner.new(client: self, store: store, logger: logger).run(on_start: on_start, &) end |