Comments (4)
@Feroks lemme know if this answers your question or if you need more info. 😄
from open.channelextensions.
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:
- With no parameters specified, and no faults,
DoA()
will continue to fill up the channel thatDoB()
is reading from and is unaware of any downstream faults. - 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 - 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:
- Any faults should bubble out to the root and can be caught.
- 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.
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.
@electricessence Thank you very much for detailed answer. It covers all my questions 🙂
from open.channelextensions.
Related Issues (20)
- Support disposable messages HOT 9
- Can we state a gradual thread increment strategy in variable max_concurrency ? HOT 1
- Ambiguous ReadAllConcurrentlyAsync signatures, when using named arguments HOT 5
- Update System.Threading.Channels HOT 2
- Batching with time limit to force data through on an interval HOT 16
- Different/Incorrect Behaviour in .NET Framework HOT 9
- Why there is prefetching in ReadUntilCancelledAsync? HOT 10
- IntelliSense not showing in VisualStudio HOT 4
- BatchingChannelReader Timer ObjectDisposedException HOT 3
- Exception handling in pipeline HOT 14
- Channels created by `Source` or `ToChannel` do not reach completion when canceled. HOT 4
- Test involving a BatchingChannelReader with 'WithTimeout' integration keeps failing HOT 5
- Multi channel multi transformation - how to do it using ChannelExtensions HOT 3
- ReadAllConcurrently completes before last task completes HOT 1
- Unbatch / Split HOT 3
- Exception handling HOT 4
- Supporting .Net 6 and up HOT 2
- Conditional package reference to System.Threading.Channels NuGet HOT 4
- IAsyncEnumerable ToChannel Extension not visible in .NET 8 projects HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from open.channelextensions.