Skip to content

Add support for TaskSchedulers in Pipe #48689

Open
@davidfowl

Description

@davidfowl

Background and Motivation

Today the pipe supports custom SynchronizationContext but doesn't support custom TaskSchedulers. We have an option to toggle if this context should be captured for all pipe operations, we have today for the SynchronizationContext.

Proposed API

namespace System.IO.Pipelines
{
    public class PipeOptions
    {
        public PipeOptions(
            MemoryPool<byte>? pool = null,
            PipeScheduler? readerScheduler = null,
            PipeScheduler? writerScheduler = null,
            long pauseWriterThreshold = -1,
            long resumeWriterThreshold = -1,
            int minimumSegmentSize = -1,
            bool useSynchronizationContext = true,
+           bool useTaskScheduler = true)

+        public bool UseTaskScheduler { get; }
    }

Alternative Designs

Turn capture on by default and people can use the ConfigureAwait pattern to disable capture, don't add the Pipe wide flag. We already have one for the sync context so it would be inconsistent.

Risks

Behavior change if there was a task scheduler that was being ignored before, it'll now be picked up for scheduling decisions.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions