MCPcopy
hub / github.com/electric-sql/pglite / detach

Method detach

packages/pglite-socket/src/index.ts:123–151  ·  view source on GitHub ↗

* Detach the current socket from this handler * @param close Whether to close the socket when detaching (overrides constructor option) * @returns this handler instance

(close?: boolean)

Source from the content-addressed store, hash-verified

121 * @returns this handler instance
122 */
123 public detach(close?: boolean): PGLiteSocketHandler {
124 this.log(`detach: detaching socket, close=${close ?? this.closeOnDetach}`)
125
126 if (!this.socket) {
127 this.log(`detach: no socket attached, nothing to do`)
128 return this
129 }
130
131 // Remove all listeners
132 this.socket.removeAllListeners('data')
133 this.socket.removeAllListeners('error')
134 this.socket.removeAllListeners('close')
135
136 // Close the socket if requested
137 if (close ?? this.closeOnDetach) {
138 if (this.socket.writable) {
139 this.log(`detach: closing socket`)
140 this.socket.end()
141 }
142 }
143
144 // Release the lock on the PGlite instance
145 this.log(`detach: releasing exclusive lock on PGlite instance`)
146 this.resolveLock?.()
147
148 this.socket = null
149 this.active = false
150 return this
151 }
152
153 /**
154 * Check if a socket is currently attached

Callers 4

handleErrorMethod · 0.95
handleCloseMethod · 0.95
stopMethod · 0.80
index.test.tsFile · 0.80

Calls 1

logMethod · 0.95

Tested by

no test coverage detected