Closed Tyrrrz closed 1 year ago
Now that I think about it, this might not be possible to implement. That's because CommandTask<T>
isn't really an async container in the same general sense as Task<T>
.
More specifically, a method with async CommandTask<T>
signature would only work if:
await
on another method returning CommandTask<T>
(probably Command.ExecuteAsync()
). Otherwise, we have nowhere to get the ProcessId
value from.await
more than one CommandTask<T>
method. Otherwise, we don't know which value of ProcessId
to use on the resulting task.I doubt C# compiler can enforce these criteria for us. Perhaps, it's more practical to continue using the existing Select()
/Bind()
abstractions.
Decided it's not really worth it
Details
Currently, some parts of CliWrap's internal code use the following patterns to build upon
CommandTask<T>
:https://github.com/Tyrrrz/CliWrap/blob/b956aaf4934ad735b3cad9d1d9d0422b11e1287c/CliWrap/Buffered/BufferedCommandExtensions.cs#L46-L76
https://github.com/Tyrrrz/CliWrap/blob/b956aaf4934ad735b3cad9d1d9d0422b11e1287c/CliWrap/EventStream/PullEventStreamCommandExtensions.cs#L65
This is because we can't use
async
/await
in methods returningCommandTask<T>
because C# compiler doesn't know how to construct instances ofCommandTask<T>
.We should be able to resolve this by implementing a custom
AsyncMethodBuilder
forCommandTask<T>
. Some resources on this topic:The method builder should probably be internal to avoid introducing unnecessary liabilities. The end user is unlikely to define methods that return
CommandTask<T>
themselves. If this issue arises in the future, we can address it then.