(options?: {
readonly disablePing?: boolean
})
| 248 | * @category construtors |
| 249 | */ |
| 250 | export const fromSocket = (options?: { |
| 251 | readonly disablePing?: boolean |
| 252 | }): Effect.Effect< |
| 253 | void, |
| 254 | never, |
| 255 | Scope.Scope | EventLog | EventLogEncryption | Socket.Socket |
| 256 | > => |
| 257 | Effect.gen(function*() { |
| 258 | const log = yield* EventLog |
| 259 | const socket = yield* Socket.Socket |
| 260 | const encryption = yield* EventLogEncryption |
| 261 | const scope = yield* Effect.scope |
| 262 | const writeRaw = yield* socket.writer |
| 263 | |
| 264 | function* writeGen(request: typeof ProtocolRequest.Type) { |
| 265 | const data = encodeRequest(request) |
| 266 | if (request._tag !== "WriteEntries" || data.byteLength <= constChunkSize) { |
| 267 | return yield* writeRaw(data) |
| 268 | } |
| 269 | const id = request.id |
| 270 | for (const part of ChunkedMessage.split(id, data)) { |
| 271 | yield* writeRaw(encodeRequest(part)) |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | const write = (request: typeof ProtocolRequest.Type) => Effect.gen(() => writeGen(request)) |
| 276 | |
| 277 | yield* Effect.gen(function*() { |
| 278 | let pendingCounter = 0 |
| 279 | const pending = new Map<number, { |
| 280 | readonly entries: ReadonlyArray<Entry> |
| 281 | readonly deferred: Deferred.Deferred<void> |
| 282 | readonly publicKey: string |
| 283 | }>() |
| 284 | const chunks = new Map<number, { |
| 285 | readonly parts: Array<Uint8Array> |
| 286 | count: number |
| 287 | bytes: number |
| 288 | }>() |
| 289 | |
| 290 | const subscriptions = yield* RcMap.make({ |
| 291 | lookup: (publicKey: string) => |
| 292 | Effect.acquireRelease( |
| 293 | Mailbox.make<RemoteEntry>(), |
| 294 | (mailbox) => |
| 295 | Effect.zipRight( |
| 296 | mailbox.shutdown, |
| 297 | Effect.ignoreLogged(write(new StopChanges({ publicKey }))) |
| 298 | ) |
| 299 | ) |
| 300 | }) |
| 301 | const identities = new WeakMap<any, typeof Identity.Service>() |
| 302 | const badPing = yield* Deferred.make<never, Error>() |
| 303 | |
| 304 | let latestPing = 0 |
| 305 | let latestPong = 0 |
| 306 | |
| 307 | if (options?.disablePing !== true) { |
no test coverage detected