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 | "network-changed";
11
12function isApplicationActiveWakeup(reason: ConnectionWakeup): boolean {
13 return (
14 reason === "application-active" ||
15 reason === "application-active-probe" ||
16 reason === "application-active-reconnect"
17 );
18}
19
20export function resetsRetryBackoff(reason: ConnectionWakeup): boolean {
21 return isApplicationActiveWakeup(reason) || reason === "network-changed";
22}
23
24// A long resume replaces the session, and the new session subscribes on its own.
25export function shouldResubscribeAfterWakeup(reason: ConnectionWakeup): boolean {
26 return reason === "application-active" || reason === "application-active-probe";
27}
28
29export class ConnectionWakeups extends Context.Service<
30 ConnectionWakeups,
31 {
32 readonly changes: Stream.Stream<ConnectionWakeup>;
33 }
34>()("@t3tools/client-runtime/connection/wakeups/ConnectionWakeups") {}
35
36const make = (service: ConnectionWakeups["Service"]) => ConnectionWakeups.of(service);
37
38export const layer = (service: ConnectionWakeups["Service"]) =>
39 Layer.succeed(ConnectionWakeups, make(service));