I am confused about the difference between sending items through Post() or SendAsync(). My understanding is that in all cases once an item reached the input buffer of a data block, control is returned to the calling context, correct? Then why would I ever need SendAsync? If my assumption is incorrect then I wonder, on the contrary, why anyone would ever use Post() if the whole idea of using data blocks is to establish a concurrent and async environment.
I understand of course the difference technically in that Post() returns a bool whereas SendAsync returns an awaitable Task of bool. But what implications does that have? When would the return of a bool (which I understand is a confirmation whether the item was placed in the queue of the data block or not) ever be delayed? I understand the general idea of the async/await concurrency framework but here it does not make a whole lot sense because other than a bool the results of whatever is done to the passed-in item is never returned to the caller but instead placed in an "out-queue" and either forwarded to linked data blocks or discarded.
And is there any performance difference between the two methods when sending items?
The documentation makes this reasonably clear, IMO. In particular, for
Post
:And:
In other words, while both are asynchronous with respect to processing the message,
SendAsync
allows the target block to decide whether or not to accept the message asynchronously too.It sounds like
SendAsync
is a generally "more asynchronous" approach, and one which is probably encouraged in general. What isn't clear to me is why both are required, as it certainly sounds likePost
is broadly equivalent to usingSendAsync
and then just waiting on the result.To see the difference, you need a situation where blocks will postpone their messages. In this case,
Post
will returnfalse
immediately, whereasSendAsync
will return aTask
that will be completed when the block decides what to do with the message. TheTask
will have atrue
result if the message is accepted, and afalse
result if not.One example of a postponing situation is a non-greedy join. A simpler example is when you set
BoundedCapacity
: