Giter Club home page Giter Club logo

Comments (12)

electricessence avatar electricessence commented on May 31, 2024

Ok. I'll investigate.

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

Did you experience this bug with 3.3.2?

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

This test passes: https://github.com/electricessence/Open.ChannelExtensions/blob/master/Open.ChannelExtensions.Tests/BatchTests.cs#L112-L153

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

Now that the other bug is fixed, you should be able to 'flush' the reader periodically with a timer/interval.

var c = Channel.CreateUnbounded<int>(new UnboundedChannelOptions { SingleReader = false, SingleWriter = false });

var reader = c.Reader.Batch(2);
Task.Run(async ()=>{
  await Task.Delay(1000);
  while(!reader.Completion.IsCompleted)
  {
    reader.ForceBatch();
    await Task.Delay(1000);
  }
});
await reader.ReadAllAsync(()=>{/*...*/});

from open.channelextensions.

alexeynikitin avatar alexeynikitin commented on May 31, 2024

Here's my example:

var c = Channel.CreateUnbounded<int>(new UnboundedChannelOptions { SingleReader = false, SingleWriter = false });
var reader = c.Reader.Batch(3);
Task.Run(async () =>
{
    await Task.Delay(1000);
    c.Writer.TryWrite(1);
    c.Writer.TryWrite(2);
    c.Writer.TryWrite(3);
    c.Writer.TryWrite(4);
    c.Writer.TryWrite(5);

    await Task.Delay(3000);
    Console.WriteLine(reader.ForceBatch());
});

await reader.ReadAllAsync(async batch =>
{
    Console.WriteLine($"Batch: {string.Join(",", batch.Select(i => i.ToString()))}");
    await Task.Delay(500);
});

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

K. Adding to tests.

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

Thanks again for helping with this. This is a tricky one, that if the implementation was to buffer all incomming channel content to another channel then it probably wouldn't be an issue.
I want to retain the BatchingChannelReader as a 'reader' that only pulls from it's source and subsequently batches on demand. As you might imagine, there could be unintended side effects if that wasn't the case.

The difference between your test and mine is that mine delays the read operation and yours doesn't.
Yours reveals a situation that would only occur with .ForceBatch() where I'm 'awaiting' the source before proceeding but because the source doesn't have anything new, the await is stuck.
What I was trying to avoid before was having to double await which typically requires a Task.WhenAny instead of simply awaiting a ValueTask.

Again, appreciate the help. I'm investigating further to find a solution.

from open.channelextensions.

alexeynikitin avatar alexeynikitin commented on May 31, 2024

I can suggest that BatchingChannelReader could actually work with "wrapped" items and `.ForceBatch' could post some predefined "command" item that cause completion of the batch. Then you don't need to mess with tasks.

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

The problem is, when implementing the buffer differently, the code is quite simple and without any additional contention. But as soon as I add the .ForceBatch() method, everything gets way more complex and ultimately less performant because of contention.

Still working on it.

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

Released an update.
https://www.nuget.org/packages/Open.ChannelExtensions/3.4.0

I tried a few different methods. I'm not 100% happy with having to create Tasks under the hood, but it's actually not too terrible. It does work as expected. All tests are passing.

I avoided incurring the same overhead on the Join operation and implemented some minor improvements I should have already.

from open.channelextensions.

electricessence avatar electricessence commented on May 31, 2024

@alexeynikitin Thanks again. Lemme know if there's anything else.

from open.channelextensions.

alexeynikitin avatar alexeynikitin commented on May 31, 2024

@electricessence Ok, thank you!

from open.channelextensions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.