Skip to content

Commit

Permalink
fix: allow typing job options in peer queue (#2372)
Browse files Browse the repository at this point in the history
Allows specifying the job option type as a generic.
  • Loading branch information
achingbrain authored Jan 24, 2024
1 parent dbc92ab commit 74fb567
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/utils/src/peer-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { Queue, type QueueAddOptions } from './queue/index.js'
import type { Job } from './queue/job.js'
import type { PeerId } from '@libp2p/interface'

export interface PeerQueueOptions extends QueueAddOptions {
export interface PeerQueueJobOptions extends QueueAddOptions {
peerId: PeerId
}

/**
* Extends Queue to add support for querying queued jobs by peer id
*/
export class PeerQueue<JobReturnType = void> extends Queue<JobReturnType, PeerQueueOptions> {
export class PeerQueue<JobReturnType = void, JobOptions extends PeerQueueJobOptions = PeerQueueJobOptions> extends Queue<JobReturnType, JobOptions> {
has (peerId: PeerId): boolean {
return this.find(peerId) != null
}

find (peerId: PeerId): Job<PeerQueueOptions, JobReturnType> | undefined {
find (peerId: PeerId): Job<JobOptions, JobReturnType> | undefined {
return this.queue.find(job => {
return peerId.equals(job.options.peerId)
})
Expand Down

0 comments on commit 74fb567

Please sign in to comment.