MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / subscribe

Method subscribe

crates/opencode-core/src/bus.rs:70–90  ·  view source on GitHub ↗
(&self, def: &BusEventDef, callback: F)

Source from the content-addressed store, hash-verified

68 }
69
70 pub async fn subscribe<F>(&self, def: &BusEventDef, callback: F) -> u64
71 where
72 F: Fn(&str, serde_json::Value) + Send + Sync + 'static,
73 {
74 let id = {
75 let mut next = self.next_id.write().await;
76 *next += 1;
77 *next
78 };
79
80 let mut subscribers = self.subscribers.write().await;
81 let subs = subscribers
82 .entry(def.event_type.to_string())
83 .or_insert_with(Vec::new);
84 subs.push(Subscription {
85 id,
86 callback: Box::new(callback),
87 });
88
89 id
90 }
91
92 pub async fn unsubscribe(&self, event_type: &str, id: u64) {
93 let mut subscribers = self.subscribers.write().await;

Callers 2

handle_debug_commandFunction · 0.45
subscribe_channelMethod · 0.45

Calls 1

newFunction · 0.85

Tested by

no test coverage detected