MCPcopy
hub / github.com/socketio/socket.io / doClose

Method doClose

packages/engine.io/lib/transports/polling.ts:346–374  ·  view source on GitHub ↗

* Closes the transport. * * @private

(fn: () => void)

Source from the content-addressed store, hash-verified

344 * @private
345 */
346 override doClose(fn: () => void) {
347 debug("closing");
348
349 let closeTimeoutTimer;
350
351 if (this.dataReq) {
352 debug("aborting ongoing data request");
353 this.dataReq.destroy();
354 }
355
356 const onClose = () => {
357 clearTimeout(closeTimeoutTimer);
358 fn();
359 this.onClose();
360 };
361
362 if (this.writable) {
363 debug("transport writable - closing right away");
364 this.send([{ type: "close" }]);
365 onClose();
366 } else if (this.discarded) {
367 debug("transport discarded - closing right away");
368 onClose();
369 } else {
370 debug("transport not writable - buffering orderly close");
371 this.shouldClose = onClose;
372 closeTimeoutTimer = setTimeout(onClose, this.closeTimeout);
373 }
374 }
375
376 /**
377 * Returns headers for a response.

Callers 1

closeFunction · 0.45

Calls 4

sendMethod · 0.95
debugFunction · 0.85
onCloseFunction · 0.50
destroyMethod · 0.45

Tested by

no test coverage detected