MCPcopy
hub / github.com/tldraw/tldraw / connect

Method connect

apps/dotcom/sync-worker/src/postgres.ts:69–104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 ) {}
68
69 async connect(): Promise<PostgresPoolClient> {
70 const prevLock = this._lock
71 const released = promiseWithResolve<void>()
72 this._lock = released
73
74 await prevLock
75
76 const client = new pg.Client({
77 connectionString: this.env.BOTCOM_POSTGRES_POOLED_CONNECTION_STRING,
78 application_name: 'user-do',
79 keepAlive: false,
80 })
81
82 try {
83 await client.connect()
84 } catch (e) {
85 released.resolve(undefined)
86 throw e
87 }
88
89 return {
90 query: (...args: any[]) => (client.query as any)(...args),
91 release() {
92 client.end().catch(() => {})
93 // Forcefully destroy the TCP socket so it doesn't linger
94 // and block Durable Object hibernation. The graceful end()
95 // above sends the PG Terminate message; destroy() ensures
96 // the socket handle is removed from the event loop immediately.
97 const stream = (client as any).connection?.stream
98 if (stream && typeof stream.destroy === 'function') {
99 stream.destroy()
100 }
101 released.resolve(undefined)
102 },
103 } as PostgresPoolClient
104 }
105
106 async end() {
107 await this._lock

Callers

nothing calls this directly

Calls 3

promiseWithResolveFunction · 0.90
connectMethod · 0.65
resolveMethod · 0.65

Tested by

no test coverage detected