Flowing context
Currently a faulted instance doesn't carry any context (other than the exception). It can be somewhat limiting. The only thing you can really do with one is log the exception itself, but multiple Try instances you don't know the origin of it.
I'm not sure what's the appropriate solution here, but do you see this as an issue that needs a solution?
I can imagine adding a Try<TInput, TResult> (which can also avoid capturing):
var block =
new TransformBlock<string, Try<string, string>>(
uri => Try.Create(uri, innerUri => client.GetStringAsync(innerUri)));
I can make that a PR if you're interested. WDYT?
This should be solvable by using ExceptionDispatchInfo, I believe.
Sorry for the silence! For some reason GH never notified me of this issue, so I just saw it...
You bring up a good point, and one which makes sense. I've had similar wants when using dataflow (even without Try), so I wonder if a separate solution would be better. Have to think about this for a bit.
As a workaround, can Exception.Data be used?
var block1 = new TransformBlock<Try<int>, Try<string>>(msg =>
{
return msg.Map(value =>
{
try
{
if (value > 2)
{
throw new Exception("blech");
}
return value.ToString();
}
catch (Exception ex)
{
ex.Data["block1.state"] = value;
throw;
}
});
});