Skip to content

Commit

Permalink
move process limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
Bossett committed Sep 5, 2024
1 parent 6b8ad64 commit b54d958
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/util/subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Database } from '../db'
import { Mutex } from 'async-mutex'

const includedRecords = new Set(['app.bsky.feed.post'])
let runningEvents = 0

export abstract class FirehoseSubscriptionBase {
public sub: Subscription<RepoEvent>
Expand All @@ -37,7 +38,7 @@ export abstract class FirehoseSubscriptionBase {
const delay = (ms: number) => new Promise((res) => setTimeout(res, ms))
const mutex = new Mutex()

let runningEvents = 0
await mutex.runExclusive(() => (runningEvents = 0))

try {
for await (const evt of this.sub) {
Expand All @@ -58,7 +59,7 @@ export abstract class FirehoseSubscriptionBase {

this.handleEvent(evt).finally(async () => {
await mutex.runExclusive(async () => {
runningEvents--
if (runningEvents > 0) runningEvents--
})
})

Expand Down

0 comments on commit b54d958

Please sign in to comment.