Skip to content

How to write a single line to StandardInputPipe once only? #150

Answered by El-Gor-do
El-Gor-do asked this question in Q&A
Discussion options

You must be logged in to vote

How I've ended up doing it is to create my own BlockingPipeSource (not sure if this is the right name) using the AsyncCollection blocking collection from Stephen Cleary's Nito.AsyncEx.Coordination Nuget package:

public class BlockingPipeSource : PipeSource
{
    private AsyncCollection<string> Buffer { get; }

    public BlockingPipeSource()
    {
        this.Buffer = new AsyncCollection<string>();
    }

    public override async Task CopyToAsync(Stream destination, CancellationToken cancellationToken = default)
    {
        while (!cancellationToken.IsCancellationRequested)
        {
            // wait until there is a value to write
            string value = await this.Buffer.TakeA…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@Tyrrrz
Comment options

Comment options

You must be logged in to vote
1 reply
@ehabhussein
Comment options

Answer selected by Tyrrrz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants