Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

1.0 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { mapSettledWithConcurrency } from './map-with-concurrency'

describe('mapSettledWithConcurrency', () => {
  it('preserves all-settled results and order while bounding a large fanout', async () => {
    const limit = 7
    const items = Array.from({ length: 1_000 }, (_, index) => index)
    let inFlight = 0
    let peak = 0

    const results = await mapSettledWithConcurrency(items, limit, async (item) => {
      inFlight += 1
      peak = Math.max(peak, inFlight)
      await Promise.resolve()
      for (let turn = 0; turn < item % 5; turn += 1) {
        await Promise.resolve()
      }
      inFlight -= 1
      if (item % 97 === 0) {
        throw `rejected-${item}`
      }
      return `fulfilled-${item}`
    })

    expect(peak).toBe(limit)
    expect(results).toEqual(
      items.map((item): PromiseSettledResult<string> =>
        item % 97 === 0
          ? { status: 'rejected', reason: `rejected-${item}` }
          : { status: 'fulfilled', value: `fulfilled-${item}` }
      )
    )
  })
})