| 513 | } |
| 514 | |
| 515 | class BulkUnregistrationImpl implements BulkUnregistration { |
| 516 | |
| 517 | private _unregistrations: Map<string, Unregistration> = new Map<string, Unregistration>(); |
| 518 | |
| 519 | constructor(private _connection: IConnection | undefined, unregistrations: Unregistration[]) { |
| 520 | unregistrations.forEach(unregistration => { |
| 521 | this._unregistrations.set(unregistration.method, unregistration); |
| 522 | }); |
| 523 | } |
| 524 | |
| 525 | public get isAttached(): boolean { |
| 526 | return !!this._connection; |
| 527 | } |
| 528 | |
| 529 | public attach(connection: IConnection): void { |
| 530 | this._connection = connection; |
| 531 | } |
| 532 | |
| 533 | public add(unregistration: Unregistration): void { |
| 534 | this._unregistrations.set(unregistration.method, unregistration); |
| 535 | } |
| 536 | |
| 537 | public dispose(): any { |
| 538 | let unregistrations: Unregistration[] = []; |
| 539 | for (let unregistration of this._unregistrations.values()) { |
| 540 | unregistrations.push(unregistration); |
| 541 | } |
| 542 | let params: UnregistrationParams = { |
| 543 | unregisterations: unregistrations |
| 544 | }; |
| 545 | this._connection!.sendRequest(UnregistrationRequest.type, params).then(undefined, (_error) => { |
| 546 | this._connection!.console.info(`Bulk unregistration failed.`); |
| 547 | }); |
| 548 | } |
| 549 | |
| 550 | public disposeSingle(arg: string | RPCMessageType): boolean { |
| 551 | const method = Is.string(arg) ? arg : arg.method; |
| 552 | |
| 553 | const unregistration = this._unregistrations.get(method); |
| 554 | if (!unregistration) { |
| 555 | return false; |
| 556 | } |
| 557 | |
| 558 | let params: UnregistrationParams = { |
| 559 | unregisterations: [unregistration] |
| 560 | } |
| 561 | this._connection!.sendRequest(UnregistrationRequest.type, params).then(() => { |
| 562 | this._unregistrations.delete(method); |
| 563 | }, (_error) => { |
| 564 | this._connection!.console.info(`Unregistering request handler for ${unregistration.id} failed.`); |
| 565 | }); |
| 566 | return true; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | /** |
| 571 | * Interface to register and unregister `listeners` on the client / tools side. |
nothing calls this directly
no outgoing calls
no test coverage detected