Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

feat!: added method to cancel a pending dial by it's id #383

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/interface-connection-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,18 @@ export interface ConnectionManager {
* ```
*/
getDialQueue: () => PendingDial[]

/**
* Cancel a pending dial by removing it from the queue and rejecting all promises associated with it
*
* @param {string} id - The id of the dial to cancel
*
* @example
*
* ```js
* const dialId = libp2p.connectionManager.getDialQueue()[0].id
* libp2p.connectionManager.cancelDial(dial-id)
* ```
*/
cancelDial: (id: string) => void
}
12 changes: 12 additions & 0 deletions packages/interface-libp2p/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,18 @@ export interface Libp2p extends Startable, EventEmitter<Libp2pEvents> {
*/
getDialQueue: () => PendingDial[]

/**
* Cancel a pending dial by its id
*
* @example
*
* ```js
* const dialId = libp2p.getDialQueue()[0].id
* libp2p.cancelDial(dialId)
* ```
*/
cancelDial: (id: string) => void

/**
* Return a list of all peers we currently have a connection open to
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/interface-mocks/src/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ class MockConnectionManager implements ConnectionManager, Startable {
getDialQueue (): PendingDial[] {
return []
}

cancelDial (): void {}
}

export function mockConnectionManager (components: MockConnectionManagerComponents): ConnectionManager {
Expand Down