Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

thread-outbox.ts

39 lines1.4 KB

1import type { EnvironmentId } from "@t3tools/contracts";
2​
3import { appAtomRegistry } from "./atom-registry";
4import { createThreadOutboxManager } from "./thread-outbox-manager";
5import type { QueuedThreadMessage } from "./thread-outbox-model";
6import { expoThreadOutboxStorage } from "./thread-outbox-storage";
7​
8export * from "./thread-outbox-model";
9​
10export const threadOutboxManager = createThreadOutboxManager({
11 registry: appAtomRegistry,
12 storage: expoThreadOutboxStorage,
13});
14​
15export function ensureThreadOutboxLoaded(): void {
16 void threadOutboxManager.load();
18​
19export function enqueueThreadOutboxMessage(message: QueuedThreadMessage): Promise<void> {
20 return threadOutboxManager.enqueue(message);
22​
23/** Waits for pending writes to settle; false if the message was rolled back. */
24export function confirmThreadOutboxMessageQueued(message: QueuedThreadMessage): Promise<boolean> {
25 return threadOutboxManager.confirmQueued(message);
27​
28/** Rewrite a queued message; no-op (false) if it was removed in the meantime. */
29export function updateThreadOutboxMessage(message: QueuedThreadMessage): Promise<boolean> {
30 return threadOutboxManager.update(message);
32​
33export function removeThreadOutboxMessage(message: QueuedThreadMessage): Promise<void> {
34 return threadOutboxManager.remove(message);
36​
37export function clearThreadOutboxEnvironment(environmentId: EnvironmentId): Promise<void> {
38 return threadOutboxManager.clearEnvironment(environmentId);