Skip to content

Fix detached limit.map calls - #108

Merged
sindresorhus merged 1 commit into
sindresorhus:mainfrom
rajanpanth:fix/detached-map
Jul 20, 2026
Merged

sindresorhus merged 1 commit into
sindresorhus:mainfrom
rajanpanth:fix/detached-map

Conversation

@rajanpanth

Copy link
Copy Markdown
Contributor

Summary

  • make limit.map use the limiter it belongs to instead of its call-time receiver
  • cover detached map calls sharing the limiter's configured concurrency with direct tasks

Problem

LimitFunction.map is exposed as a callable function property, but its implementation invokes the limiter through dynamic this. A valid detached call such as const {map} = limit therefore rejects with TypeError: this is not a function.

Fix

Use the closed-over generator function when scheduling mapped items. This preserves the existing concurrency, ordering, iterable, and index behavior without requiring a bound receiver.

The regression test combines a direct limiter call with a detached map call and verifies their shared maximum concurrency remains at the configured limit.

Testing

  • npm exec ava -- --match='map works when detached from the limit'
  • npm exec ava
  • AVA suite on Node.js 20, 22, and 24
  • npm exec tsd
  • npm exec xo -- index.js test.js

The aggregate npm test command was also attempted. On this Windows checkout, XO reports its existing TypeScript project-service lookup error for index.d.ts and index.test-d.ts; the same error occurs on the untouched base. The changed JavaScript files pass XO.

@sindresorhus
sindresorhus merged commit ef37eb2 into sindresorhus:main Jul 20, 2026
3 checks passed
hitoshikumagai added a commit to hitoshikumagai/cd14715-claude-code-classroom that referenced this pull request Nov 7, 2026
…ew run

Running against sindresorhus/p-limit#108 surfaced several problems:

- Retired model: SDK 0.1 maps the 'sonnet' alias to a retired model ID
  (404). Subagents now inherit ANTHROPIC_MODEL; examples use
  claude-sonnet-5-5.
- SDK 0.1 duplicated tool_use ids after parallel tool calls with current
  models (400). Upgrade @anthropic-ai/claude-agent-sdk to ^0.3.319, which
  requires zod v4: replace zod-to-json-schema with z.toJSONSchema
  (target draft-7, since the CLI rejects the 2020-12 $schema) and use the
  two-argument z.record.
- The Agent tool (formerly Task) runs subagents in the background by
  default, so the orchestrator re-spawned them and polled. The prompt now
  requires run_in_background: false in a single message, built-in tools
  are limited to Agent and Skill, and GitHub MCP tools load up front.
- Stop on non-retryable API errors instead of looping to maxTurns on
  every retry; withRetry skips errors marked retryable: false.
- Fetch files by head SHA (head branch may be on a fork) and disallow
  the GitHub MCP server's write tools.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants