When I was looked at asynchronous pattern PipeTo for Akka.NET I found example where author uses TaskContinuationOptions and operator &. Is it an erorr or may be it is a propper way to use '&' with Akka.NET and a PipeTo?
For better explain: AttachedToParent & ExecuteSynchronously gave 0 and the inner lambda would be invoked as asyncronosly task.
/// When no continuation options are specified, specifies that default behavior should be used when executing a continuation. The continuation runs asynchronously when the antecedent task completes, regardless of the antecedent's final property value. It the continuation is a child task, it is created as a detached nested task.
None = 0,
AttachedToParent = 4,
ExecuteSynchronously = 524288, // 0x00080000
The question should be there "&" or "|" operator?
TL;DR:
Yes. The author should have used |
instead of &
.
LONG ANSWER:
Bitwise AND => The resulting bit is 1 only if both compared bits are 1.
Bitwise OR => The resulting bit is 1 if any of the two compared bits is 1.
So you first want to translate the numbers to binary (I'll add some 0's to make the comparison easier):
None
)PreferFairness
)LongRunning
)AttachedToParent
)NotOnRanToCompletion
)NotOnFaulted
)OnlyOnCanceled
)NotOnCanceled
)OnlyOnFaulted
)OnlyOnFaulted
)ExecuteSynchronously
)Now you know, for example, that OnlyOnCanceled
is the same as NotOnFaulted
+ NotOnRanToCompletion
.
Or, using bitwise operators: NotOnFaulted | NotOnRanToCompletion
.
On the other hand NotOnFaulted & NotOnRanToCompletion
is equal to 0
, that corresponds to None
.
While OnlyOnCanceled & NotOnFaulted == NotOnRanToCompletion
.
So the answer is: when you want to combine, use |
. When you want to get the difference, use &
.
I hope this example made it clearer.