UNPKG

@ginden/blinkstick-v2

Version:
35 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.blinkstickFinalizationRegistry = void 0; const lib_usb_transport_1 = require("../transport/lib-usb-transport"); const transport_1 = require("../transport"); /** * @summary A FinalizationRegistry instance to ensure that HIDAsync devices are closed properly * @category Implementation details */ exports.blinkstickFinalizationRegistry = new FinalizationRegistry((hidDevice) => { if (hidDevice instanceof lib_usb_transport_1.LibUsbTransport) { process.emitWarning(`LIBUSB device was not closed properly. Ensure call to Blinkstick.close() before it's garbage collected.`); hidDevice.close().catch((err) => { setImmediate(() => { throw err; }); }); } else if (hidDevice instanceof transport_1.NodeHidAsyncTransport) { // Access undocumented _closed property to check if the device is already closed const isClosed = hidDevice.device._closed; if (isClosed) { return; } else { process.emitWarning(`HID device was not closed properly. Ensure call to Blinkstick.close() before it's garbage collected.`); hidDevice.close().catch((err) => { setImmediate(() => { throw err; }); }); } } }); //# sourceMappingURL=blinkstick-finalization-registry.js.map