Skip to content

[Context]: add MapInContextAsync collection transform #18

Description

@rian-be

Summary

Add MapInContextAsync — an async LINQ-like transform of IEnumerable<TIn> → results, where each item's transform runs inside a safe context scope.

Goal

Provide a clean, readable alternative to a hand-written Select(...) + Task.WhenAll loop that loses/leaks ambient context.

Problem

The current parallel primitives are single-action or all-delegates. Transforming a collection item-by-item with proper context isolation is boilerplate and error-prone:

// ❌ manual
var tasks = items.Select(i => manager.ExecuteInContext(ctx, () => Transform(i)));
var results = await Task.WhenAll(tasks);

Scope

  • IContextManager<C>.MapInContextAsync(C ctx, IEnumerable<TIn>, Func<TIn,Task<TOut>>).
  • Each item transformed under its own context snapshot (isolation, no ambient write).
  • Result order preserved by default (see the Ordered/Unordered issue for opt-out).
  • Unit tests for context flow, isolation, and order.

Design Expectations

  • Composes with the base fork-join execution primitive.
  • Reuses per-item BeginContext/snapshot; no new runtime primitive.
  • Async-only; ConfigureAwait(false) internally.

Acceptance Criteria

  • Collection transforms with correct per-item context isolation.
  • Order of results matches input order by default.
  • No behavior change for a single-item input.

Non-Goals

  • No concurrency limiting (lives in MapParallel/MaxConcurrency).
  • No partial-success handling (lives in TryEach).
  • No chunking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    concurrencyParallel / batch / async executionenhancementNew feature or requestextensionExtension behaviors / helpers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions