MCPcopy Create free account
hub / github.com/TanStack/db / withTimeout

Function withTimeout

packages/electron-db-sqlite-persistence/src/renderer.ts:41–66  ·  view source on GitHub ↗
(
  promise: Promise<T>,
  timeoutMs: number,
  timeoutMessage: string,
)

Source from the content-addressed store, hash-verified

39}
40
41function withTimeout<T>(
42 promise: Promise<T>,
43 timeoutMs: number,
44 timeoutMessage: string,
45): Promise<T> {
46 if (timeoutMs <= 0) {
47 return promise
48 }
49
50 return new Promise<T>((resolve, reject) => {
51 const timer = setTimeout(() => {
52 reject(new InvalidPersistedCollectionConfigError(timeoutMessage))
53 }, timeoutMs)
54
55 promise.then(
56 (value) => {
57 clearTimeout(timer)
58 resolve(value)
59 },
60 (error: unknown) => {
61 clearTimeout(timer)
62 reject(error)
63 },
64 )
65 })
66}
67
68function assertValidResponse(
69 response: ElectronPersistenceResponseEnvelope,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected