| 387 | return EventJournal.of({ |
| 388 | entries: Effect.sync(() => journal.slice()), |
| 389 | write({ effect, event, payload, primaryKey }) { |
| 390 | return Effect.acquireUseRelease( |
| 391 | Effect.sync(() => |
| 392 | new Entry({ |
| 393 | id: makeEntryIdUnsafe(), |
| 394 | event, |
| 395 | primaryKey, |
| 396 | payload |
| 397 | }, { disableChecks: true }) |
| 398 | ), |
| 399 | effect, |
| 400 | (entry, exit) => |
| 401 | Effect.suspend(() => { |
| 402 | if (exit._tag === "Failure" || byId.has(entry.idString)) return Effect.void |
| 403 | journal.push(entry) |
| 404 | byId.set(entry.idString, entry) |
| 405 | remotes.forEach((remote) => { |
| 406 | remote.missing.push(entry) |
| 407 | }) |
| 408 | return PubSub.publish(pubsub, entry) |
| 409 | }) |
| 410 | ) |
| 411 | }, |
| 412 | writeFromRemote: Effect.fnUntraced(function*(options) { |
| 413 | const remote = ensureRemote(options.remoteId) |
| 414 | const uncommittedRemotes: Array<RemoteEntry> = [] |