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

wakeups.ts

34 lines1.1 KB

1import * as Context from "effect/Context";
2import * as Layer from "effect/Layer";
3import type * as Stream from "effect/Stream";
4​
5export type ConnectionWakeup =
6 | "application-active"
7 | "application-active-probe"
8 | "application-active-reconnect"
9 | "credentials-changed";
10​
11export function isApplicationActiveWakeup(reason: ConnectionWakeup): boolean {
12 return (
13 reason === "application-active" ||
14 reason === "application-active-probe" ||
15 reason === "application-active-reconnect"
16 );
18​
19// A long resume replaces the session, and the new session subscribes on its own.
20export function shouldResubscribeAfterWakeup(reason: ConnectionWakeup): boolean {
21 return reason === "application-active" || reason === "application-active-probe";
23​
24export class ConnectionWakeups extends Context.Service<
25 ConnectionWakeups,
26 {
27 readonly changes: Stream.Stream<ConnectionWakeup>;
28 }
29>()("@t3tools/client-runtime/connection/wakeups/ConnectionWakeups") {}
30​
31const make = (service: ConnectionWakeups["Service"]) => ConnectionWakeups.of(service);
32​
33export const layer = (service: ConnectionWakeups["Service"]) =>
34 Layer.succeed(ConnectionWakeups, make(service));