| 363 | } |
| 364 | |
| 365 | async function end({ timeout = null } = {}) { |
| 366 | if (ending) |
| 367 | return ending |
| 368 | |
| 369 | await 1 |
| 370 | let timer |
| 371 | return ending = Promise.race([ |
| 372 | new Promise(r => timeout !== null && (timer = setTimeout(destroy, timeout * 1000, r))), |
| 373 | Promise.all(connections.map(c => c.end()).concat( |
| 374 | listen.sql ? listen.sql.end({ timeout: 0 }) : [], |
| 375 | subscribe.sql ? subscribe.sql.end({ timeout: 0 }) : [] |
| 376 | )) |
| 377 | ]).then(() => clearTimeout(timer)) |
| 378 | } |
| 379 | |
| 380 | async function close() { |
| 381 | await Promise.all(connections.map(c => c.end())) |