Giter Club home page Giter Club logo

Comments (4)

electricessence avatar electricessence commented on June 1, 2024 1

@Feroks lemme know if this answers your question or if you need more info. 😄

from open.channelextensions.

electricessence avatar electricessence commented on June 1, 2024

This is a great question by which the subtleties of I have struggled greatly!

Keep in mind that with your code, await Finish() is called for every entry until there if a fault.

There are some tests to prove the policy, but basically:

  1. With no parameters specified, and no faults, DoA() will continue to fill up the channel that DoB() is reading from and is unaware of any downstream faults.
  2. If DoB() throws for any reason, the underlying read marks complete the subsequent writer with the exception thrown. https://github.com/Open-NET-Libraries/Open.ChannelExtensions/blob/master/Open.ChannelExtensions/Extensions.Pipe.cs#L105
  3. The 'faulted' downstream reader will then throw (out to the root statement) once it attempts to wait for any more items. https://github.com/Open-NET-Libraries/Open.ChannelExtensions/blob/master/Open.ChannelExtensions/Extensions.Read.cs#L108

So to summarize:

  1. Any faults should bubble out to the root and can be caught.
  2. With "Pipe" operations, upstream channels (and pipe calls) are unaware of downstream faults. It is possible to have multiple .Pipe calls on a single reader.

from open.channelextensions.

electricessence avatar electricessence commented on June 1, 2024

Am i supposed to try/catch all exceptions in Pipe methods and then return some faulty code that is handled by Filter method?
It depends.

The only real consequence is that the most upstream channel will continue iterating without being notified of a problem.
This would also be true for Dataflow blocks.

Here's a pattern you could and probably should use in a complex situation like the one you provided:

using var ts = new CancellationTokenSource();
try
{
   await .....
   .ToChannel()
   .PipeAsync(async x =>
   {
      return await DoA();
   }, cancellationToken: ts.Token)
   .PipeAsync(async x =>
   {
      return await DoB();
   }, cancellationToken: ts.Token)
   .ReadAllAsync(x => 
   {
      await Finish();
   });
}
catch
{
  ts.Cancel(); // Any fault will halt (cancel) the above pipe operations.
  throw;
}

That way any downstream fault signals that the upstream reads/transforms are simply wasting processes.

from open.channelextensions.

Feroks avatar Feroks commented on June 1, 2024

@electricessence Thank you very much for detailed answer. It covers all my questions 🙂

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.