* Removes exactly the callback registered under `subscriptionId` (as * returned by addCallback). A no-op if already removed — including * once the connection is closed, since _failPending() has already cleaned * up local state at that point (and there is no remote end left to reach:
(subscriptionId)
| 459 | * @returns {Promise<void>} |
| 460 | */ |
| 461 | async removeCallback(subscriptionId) { |
| 462 | const entry = this._callbacks.get(subscriptionId) |
| 463 | if (entry === undefined) { |
| 464 | return |
| 465 | } |
| 466 | |
| 467 | if (entry.removing === undefined) { |
| 468 | entry.removing = (async () => { |
| 469 | const response = await this.send({ |
| 470 | method: 'session.unsubscribe', |
| 471 | params: { subscriptions: [subscriptionId] }, |
| 472 | }) |
| 473 | if (response?.error !== undefined) { |
| 474 | throw new Error(`${response.error}: ${response.message}`) |
| 475 | } |
| 476 | this._callbacks.delete(subscriptionId) |
| 477 | this.off(entry.method, entry.handler) |
| 478 | })().finally(() => { |
| 479 | entry.removing = undefined |
| 480 | }) |
| 481 | } |
| 482 | |
| 483 | return entry.removing |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Close ws connection. |
no test coverage detected