Open History to see the last commit
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 );
17}
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";
22}
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));