Skip to content

Commit

Permalink
fix: update p-queue types (libp2p#428)
Browse files Browse the repository at this point in the history
[email protected] contained a breaking change so update it's use to get
the correct return types.
  • Loading branch information
achingbrain authored Mar 10, 2023
1 parent a70ab3f commit f5b85fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ export class Providers implements Startable {
return [...provs.keys()].map(peerIdStr => {
return peerIdFromString(peerIdStr)
})
}, {
// no timeout is specified for this queue so it will not
// throw, but this is required to get the right return
// type since [email protected]
throwOnTimeout: true
})
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/network.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type { PeerId } from '@libp2p/interface-peer-id'
import type { Sink } from 'it-stream-types'
import { Uint8ArrayList } from 'uint8arraylist'
import map from 'it-map'
import type { Multiaddr } from '@multiformats/multiaddr'

describe('Network', () => {
let dht: DualKadDHT
Expand Down Expand Up @@ -53,7 +54,7 @@ describe('Network', () => {
const msg = new Message(MESSAGE_TYPE.PING, uint8ArrayFromString('hello'), 0)

// mock it
dht.components.connectionManager.openConnection = async (peer: PeerId) => {
dht.components.connectionManager.openConnection = async (peer: PeerId | Multiaddr) => {
// @ts-expect-error incomplete implementation
const connection: Connection = {
newStream: async (protocols: string | string[]) => {
Expand Down
4 changes: 2 additions & 2 deletions test/providers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ describe('Providers', () => {
cacheSize: 10
})

const hashes = await Promise.all([...new Array(100)].map((i: number) => {
return sha256.digest(uint8ArrayFromString(`hello ${i}`))
const hashes = await Promise.all([...new Array(100)].map(async (i: number) => {
return await sha256.digest(uint8ArrayFromString(`hello ${i}`))
}))

const cids = hashes.map((h) => CID.createV0(h))
Expand Down
4 changes: 2 additions & 2 deletions test/routing-table.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ describe('Routing Table', () => {
let fn: (() => Promise<any>) | undefined

// execute queued functions immediately
// @ts-expect-error incomplete implementation
table.pingQueue = {
// @ts-expect-error
add: async (f: () => Promise<any>) => {
fn = f
},
Expand Down Expand Up @@ -175,8 +175,8 @@ describe('Routing Table', () => {
let fn: (() => Promise<any>) | undefined

// execute queued functions immediately
// @ts-expect-error incomplete implementation
table.pingQueue = {
// @ts-expect-error
add: async (f: () => Promise<any>) => {
fn = f
},
Expand Down

0 comments on commit f5b85fc

Please sign in to comment.