public Data GetCurrent(Credentials credentials)
{
var data = new Lazy(() => GetCurrentInternal(credentials));
try
{
return data.Value
No, Lazy
is not the same as Task
.
Lazy
T
value that will be computed synchronously at first access, which may or may not occur at all.Task
T
value that will be computed (typically asynchronously) at the creation of its promise, even if nobody ends up actually accessing it.All that being said, Lazy
and Task
do have something in common that you may have already picked up.
Each of these types is a unary generic type that describes a unique way to perform a particular computation that would yield a T
value (and that computation can conveniently be passed as a delegate or lambda). In other words, each of these types is an example of a monad. You can find some very good and simple explanations of what a monad is here on Stack Overflow and elsewhere.