import { createTRPCClient, createWSClient, wsLink } from "@trpc/client";
const link = wsLink<Router>({
client: createWSClient({ url: TRPC_SERVER_URL }),
});
const client = createTRPCClient<Router>({
links: [link],
});
// assuming the trpc server is up and running
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> logs 'done'
// assuming instance1 is not available and the ws link is disconnected
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> .... [hangs forever, does not time out despite AbortSignal]
import { createTRPCClient, createWSClient, wsLink } from "@trpc/client";
const link = wsLink<Router>({
client: createWSClient({ url: TRPC_SERVER_URL }),
});
const client = createTRPCClient<Router>({
links: [link],
});
// assuming the trpc server is up and running
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> logs 'done'
// assuming instance1 is not available and the ws link is disconnected
client.hello
.query({ name: "world" }, { signal: AbortSignal.timeout(1) })
.finally(() => console.log(`done`))
// >> .... [hangs forever, does not time out despite AbortSignal]