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

wakeups.ts

38 lines1.2 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-long"
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-long"
17 );
19​
20export function resetsRetryBackoff(reason: ConnectionWakeup): boolean {
21 return isApplicationActiveWakeup(reason) || reason === "network-changed";
23​
24export function shouldResubscribeAfterWakeup(reason: ConnectionWakeup): boolean {
25 return isApplicationActiveWakeup(reason);
27​
28export class ConnectionWakeups extends Context.Service<
29 ConnectionWakeups,
30 {
31 readonly changes: Stream.Stream<ConnectionWakeup>;
32 }
33>()("@t3tools/client-runtime/connection/wakeups/ConnectionWakeups") {}
34​
35const make = (service: ConnectionWakeups["Service"]) => ConnectionWakeups.of(service);
36​
37export const layer = (service: ConnectionWakeups["Service"]) =>
38 Layer.succeed(ConnectionWakeups, make(service));