MCPcopy Create free account
hub / github.com/anomalyco/opencode / sync

Function sync

packages/opencode/src/share/share-next.ts:124–147  ·  view source on GitHub ↗
(sessionID: SessionID, data: Data[])

Source from the content-addressed store, hash-verified

122 const session = yield* Session.Service
123
124 function sync(sessionID: SessionID, data: Data[]) {
125 return Effect.gen(function* () {
126 if (disabled) return
127 const share = yield* getCached(sessionID)
128 if (!share) return
129
130 const s = yield* InstanceState.get(state)
131 const existing = s.queue.get(sessionID)
132 if (existing) {
133 for (const item of data) {
134 existing.set(key(item), item)
135 }
136 return
137 }
138
139 const next = new Map(data.map((item) => [key(item), item]))
140 s.queue.set(sessionID, next)
141 yield* flush(sessionID).pipe(
142 Effect.delay(1000),
143 Effect.catchCause((cause) => Effect.logError("share flush failed", { sessionID: sessionID, cause: cause })),
144 Effect.forkIn(s.scope),
145 )
146 })
147 }
148
149 const state: InstanceState.InstanceState<State> = yield* InstanceState.make<State>(
150 Effect.fn("ShareNext.state")(function* (_ctx) {

Callers 2

share-next.tsFile · 0.70
index.tsFile · 0.50

Calls 4

keyFunction · 0.70
getMethod · 0.65
flushFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected