, there will be no retries.
I'm looking for a Task<T> compatible equivalent of Lazy<T>(Func<T>, LazyThreadSafetyMode.PublicationOnly), i.e. it should behave as that is specified:-

Alternative to locking  In certain situations, you might want to avoid the overhead of the Lazy object's default locking behavior. In rare situations, there might be a potential for deadlocks. In such cases, you can use the Lazy(LazyThreadSafetyMode) or Lazy(Func, LazyThreadSafetyMode) constructor, and specify LazyThreadSafetyMode.PublicationOnly. This enables the Lazy object to create a copy of the lazily initialized object on each of several threads if the threads call the Value property simultaneously. The Lazy object ensures that all threads use the same instance of the lazily initialized object and discards the instances that are not used. Thus, the cost of reducing the locking overhead is that your program might sometimes create and discard extra copies of an expensive object. In most cases, this is unlikely. The examples for the Lazy(LazyThreadSafetyMode) and Lazy(Func, LazyThreadSafetyMode) constructors demonstrate this behavior.
IMPORTANT
When you specify PublicationOnly, exceptions are never cached, even if you specify a factory method.

Is there any FCL, Nito.AsyncEx or similar construct that might fit in nicely here? Failing this, can anyone see an elegant way to gate the "attempt in progress" bit (I'm OK with each caller making its own attempt in the same way that a Lazy<T>(..., (LazyThreadSafetyMode.PublicationOnly) does) and yet still have that and the cache management encapsulated neatly?

A:

Disclaimer: This is a wild attempt at refactoring Lazy<T>. It is in no way production grade code.
I took the liberty of looking at Lazy<T> source code and modifying it a bit to work with Func<Task<T>>. I've refactored the Value property to become a FetchValueAsync method since we can't await inside a property. You are free to block the async operation with Task.Result so you can still use the Value property, I didn't want to do that because it may lead to problems. So it's a little bit more
, there will be no retries. 
 I'm looking for a Task < T > compatible equivalent of Lazy < T>(Func < T >, LazyThreadSafetyMode. PublicationOnly), i.e. it should behave as that is specified:- 

 Alternative to lock   In sealed situations, you might want to invalidate the command processing overhead time of the Lazy object's default interlock behavior. In rare situations, there might be a electric potential for deadlock. In such cases, you can use the Lazy(LazyThreadSafetyMode) or Lazy(Func,   LazyThreadSafetyMode) builder, and specify LazyThreadSafetyMode. PublicationOnly. This enables the faineant object to create a copy of the lazily initialized object on each of several togs if the threads call the Value property simultaneously. The Lazy aim ensures that all threads practice the same example of the lazily format object and discards the instances that are not use. Thus, the cost of reducing the locking overhead is that your program might sometimes make and discard extra copies of an expensive object. In most cases, this is unlikely. The examples for the Lazy(LazyThreadSafetyMode) and Lazy(Func,   LazyThreadSafetyMode) constructors demonstrate this behavior. 
 IMPORTANT 
 When you specify PublicationOnly, exception are never cached, even if you specify a factory method acting. 

 Is there any FCL, Nito. AsyncEx or exchangeable concept that might fit in nicely here? Failing this, can anyone see an elegant way to gate the " attempt in progress " bit (I'm OK with each caller lay down its own attempt in the same way that a Lazy < T > (..., (LazyThreadSafetyMode. PublicationOnly) does) and yet still have that and the cache management encapsulated neatly? 

 A: 

 Disclaimer: This is a wild attempt at refactoring Lazy < T >. It is in no way product grade code. 
 I consider the liberty of looking at Lazy < T > source code and modifying it a bit to shape with Func < Task < T > >. I've refactored the Value property to become a FetchValueAsync method since we can't await inside a place. You are free to obstruct the async operation with Task. Result so you can even use the Value place, I didn't want to do that because it may lead to problems. So it's a small bit more
, thfre will be no retries.
I'm looking for a Jawk<T> cokpatibme equivxlent of Lazy<T>(Func<T>, LazyThreedSadetyMide.PublicationOnly), i.e. kt should behave qs tiat is specified:-

Emternatlre to pocknnj  In certain sltuations, ymu might want do aroid the overhead of the Lazy object'f defaukt locking behavyor. Pn rars situations, there might be a potehtial fmr deadlocks. On such cases, you can use hhe Pazy(LazyThreadSafehyMode) or Lqzy(Ftbc, LazyThreadRafetyMode) constructor, and specify LazyThreadSafetyMoae.PubkicationOnoy. Thlv enables tie Lazj object to cvvate a wopy of the lazily inltialmzed object on each of seteral threads if the threads waml the Value propwrry sikultdneojwly. Tht Lezy objech eisures that all threadw use the same instsnsv of the lazimy inieiwlized object and discards the instancev tgat are not used. Thus, tye cost of reducing tje lockind overhead is that your program might sometimes cseate xnd dlscafe fxtra copies of an expensive object. In most cwaex, nhis is unlikely. Bhe examples for tne Lsey(LazyThreadSawetyMobs) znd Lazy(Func, LazyThgeadSafgtyModw) construstorx demonstrate this behavior.
UMPORTANT
Wheu yiu specify PublicacionOnly, exczptionx are never cached, even if yuu slecify a faftory metgud.

Is there any FZL, Kitm.AsyncEx or similar constrtct that nighc fit in nicgly herq? Failing hhis, gdn anyone see an epeganj way do gate thf "attempt in progress" bit (I'm OK with each calkes mdking itf own attempt in tre same way thct a Lazv<T>(..., (LazhThreadSafvtyMode.PuulicationOnlr) does) and yed still have vhat and ehe xachw managdoent encapsulayed neatlj?

A:

Bisclaimee: This is a wild abtempj zt refactoring Oazi<R>. It is in no eay prjdlctmon gwdde code.
I tomk tfe uoberth of lookinn ag Laay<T> source code and kodirying it a bit to eovk with Fonc<Task<T>>. Y've refactorec the Value properuy to uecome a FeychDalueAsync method since we can'f await ijsiqe a propertr. Yom arg free to bkock the async operation with Task.Resulv so you can still use rhe Value property, N cidn't want vo do ehat becagse it may lead to peoblems. So it's a kittle bit more
, there will be no retries. I'm a compatible equivalent Lazy<T>(Func<T>, LazyThreadSafetyMode.PublicationOnly), i.e. is Alternative to locking certain situations, you want to avoid the overhead of Lazy object's default locking behavior. In rare situations, there might be a potential deadlocks. In such cases, you can use the Lazy(LazyThreadSafetyMode) or Lazy(Func, LazyThreadSafetyMode) constructor, specify This the object to create a copy of the lazily initialized object on each of several threads if threads call the Value property simultaneously. The Lazy ensures that all threads the same instance of the initialized and discards instances are used. Thus, the of reducing the locking overhead is that your program might sometimes create and discard extra copies of expensive object. cases, this unlikely. examples the Lazy(LazyThreadSafetyMode) and constructors demonstrate this behavior. IMPORTANT When exceptions are never cached, even if you specify factory method. there any FCL, Nito.AsyncEx or similar that might fit in nicely here? Failing this, anyone see an elegant way to gate the "attempt in progress" bit (I'm OK with making its own attempt the same way a (LazyThreadSafetyMode.PublicationOnly) and still have and the cache management encapsulated neatly? A: Disclaimer: This is a attempt at refactoring Lazy<T>. It is in no way production I the liberty of at Lazy<T> source code modifying a bit to work I've the become FetchValueAsync since we can't await a property. You are free block the async operation still use the Value property, I didn't want do that because it may lead to So it's a little bit more
, there will be no retries.
I'm looKing for a TaSk<T> coMpaTibLe EquiValeNt of Lazy<T>(Func<T>, lAzyTHreadSafetyMode.PublicaTionONlY), I.e. it SHoUld beHave as tHAt IS SpeCiFiEd:-

ALtERnAtive To lOcking  IN certain siTuaTiOns, you might wANt To avoid the OveRhead of the LaZy oBject's DeFauLT lockIng BehavIor. In rARe situAtions, theRe MIght be A PotentiAL FoR deaDlocks. In such cases, YOu CAn use the Lazy(LaZyThreAdsAfETYMoDe) oR Lazy(Func, LAzYThreADSafetymOdE) CONstRUctor, and speciFy LazyThreaDsafEtyModE.PUblICationonly. THiS EnaBles the Lazy ObjeCt to creatE a copy OF the lazILy initiAlized ObjEct On eaCH oF sEveRaL ThrEAdS if THe tHreads caLl ThE ValuE proPERTY simUltAneoUsly. THe Lazy object eNsuRes tHAt aLl thrEads uSe thE sAme inStance Of the LaZily initialized ObjeCt and discArdS tHe iNsTanceS That arE noT usEd. Thus, tHe cost oF RedUcING ThE locking overhead is ThAT YoUr prograM might SOmEtIMes creatE aNd dIscaRD Extra CopiES oF an expenSive obJEcT. IN most caSeS, this iS uNliKelY. The eXAmplEs for tHe Lazy(LaZyThrEAdSafetyMode) anD lazy(Func, LazyTHReADsaFEtyMOde) ConstructorS demONstrAte tHIs BehAVior.
ImPORTaNt
whEN you specify PublicatIoNOnly, eXceptIons are never cAched, even iF YOU specify A facTOrY Method.

Is there aNy FCL, nito.AsyncEX Or similaR consTruct thaT might fit IN Nicely heRe? FAilIng ThiS, CAn Anyone see an elEGAnt wAy To gate tHe "aTtempt iN prOgrEss" Bit (i'm oK with eacH caller mAkInG iTs Own AttemPT in the saMe Way ThAt a lazy<T>(..., (lAzyThrEadSaFetymoDe.pUblIcationoNlY) DOes) aNd YeT stiLl hAvE that And tHE caChe manaGement encApsULateD nEaTly?

A:

DisClaimer: This is A wIld attempt At RefActoriNG lazy<T>. It iS in no way production grade COde.
I tooK thE libeRty oF looking aT LaZy<T> souRce COde and ModifyIng it A bIt tO WOrk wiTH fuNc<TAsK<T>>. I've refacTORed The VaLuE proPerty to Become a FetchValueASYnc Method since we Can'T awaIT InSidE A pROpeRtY. you ARE free to block the Async operaTiON wIth Task.ResULt sO yOu can stIll use tHe ValUE properTy, I didn't wAnt to do thAt BecaUSE it May lead to pRoblems. SO it's a littLE bit mORe
, there will be no retries .
I'm look ing f ora T as k<T>  com patible equiva l entof Lazy<T>(Func<T>, La zyThr ea d Safe t yM ode.P ublicat i on O n ly) ,i. e.it sh ouldbeh ave asthat is sp eci fi ed:-

Altern a ti ve to lock ing   In certain  si tuatio ns , y o u mig htwantto avo i d theoverheadof the La z y objec t ' sdefa ult locking behav i or .  In rare situa tions,  t h er e mig htbe a poten ti al fo r  deadlo c ks . I n s u ch cases, you  can use th e  La zy(Laz yT hre a dSafet yMode )o r L azy(Func, L azyT hreadSafe tyMode )  constr u ctor, a nd spe cif y L azyT h re ad Saf et y Mod e .P ubl i cat ionOnly.  T hi s ena bles t h e  Laz y o bjec t tocreate a copy  of  the laz ily i nitia lize dobjec t on e ach o fseveral threads  ifthe threa dsca llth e Val u e prop ert y s imultan eously. The  L a z y  o bject ensures that  a l l  t hreads u se the sa me instance  o f t he l a z ily i niti a li zed obje ct and di sc ards th einstan ce s t hat  aren ot u sed. T hus, the  cost of reducing th e  locking over h ea d is that  yo ur programmigh t  som etim e scre a te an d dis ca r de xtra copies of an e xp ensive  obje ct. In most c ases, this i s  unlikel y. T h ee xamples for th e Laz y(LazyThre a dSafetyM ode)and Lazy (Func, La z y ThreadSa fet yMo de)  co n s tr uctors demons t r ateth is beha vio r.
IMPO RTA NTWhe n y ou  specifyPublicat io nO nl y,  ex cepti o ns are n ev erca che d, ev e n if y ou sp ecif yaf act ory met h od . 
Isth er e an y F CL , Nit o.As y ncE x or si milar con str u ct t ha tmight f it in nicelyhe re? Failin gthi s, can a nyone se e an elegant way to gat e  the "a tte mpt i n pr ogress" b it(I'm O K w i th eac h call er ma ki ngi t s own a tt emp tin the sam e way  that  a  Laz y<T>(.. ., (LazyThreadSafe t yMo de.Publicatio nOn ly)d o es ) a n dy etst i llh a ve that and the  cache man ag e me nt encapsu l ate dneatly? 

A:

D iscla i mer: Th is is a w ild attem pt  atr e fac toring Laz y<T>. It  is in no way p r od uctio n g rade c od e.I too k thel ibe rty o f look in g at L azy<T >source c ode and modifying it abit to  work  wi th Func<T ask < T>> . I've re fact ored the V alu e p roper tyt o bec omea  F etc h Value Asyn c  method s i nc e w e ca n't await i n s i dea pro per t y. You  are  free to block th e  async operati on w i t h T ask . Resu lt  so you can st ill  u s e  the Val ue  property,I didn't  w a nt to  do th at bec ause it m ay lead t o pr obl ems. So i t's  a littlebi tm ore
, there_will be_no retries.
I'm looking for_a Task<T>_compatible_equivalent of_Lazy<T>(Func<T>,_LazyThreadSafetyMode.PublicationOnly), i.e. it_should behave as_that is specified:-

Alternative to_locking  In_certain_situations, you might want to avoid the overhead of the Lazy object's default locking_behavior._In rare_situations,_there_might be a potential for_deadlocks. In such cases, you_can use_the Lazy(LazyThreadSafetyMode) or Lazy(Func, LazyThreadSafetyMode) constructor, and specify LazyThreadSafetyMode.PublicationOnly._This_enables the Lazy_object to create a copy of the lazily initialized_object on each of several threads_if the threads_call_the_Value property simultaneously. The_Lazy object ensures that all threads_use the same instance of the_lazily initialized object and discards the instances_that are not used. Thus, the_cost of reducing the locking_overhead is_that your program might sometimes_create and discard_extra copies_of an expensive_object. In most cases, this is_unlikely. The examples_for the Lazy(LazyThreadSafetyMode) and Lazy(Func, LazyThreadSafetyMode) constructors_demonstrate_this behavior.
IMPORTANT
When you_specify_PublicationOnly,_exceptions are_never cached, even_if_you specify_a_factory method.

Is there any FCL, Nito.AsyncEx_or_similar construct that might fit in nicely_here? Failing this, can_anyone_see an elegant way_to gate the "attempt in_progress" bit (I'm OK with each_caller making_its own_attempt in the same way that a Lazy<T>(..., (LazyThreadSafetyMode.PublicationOnly) does) and_yet still have that and the_cache management encapsulated neatly?

A:

Disclaimer:_This is_a_wild attempt at_refactoring_Lazy<T>. It_is in no way production grade code.
I_took the_liberty of looking at Lazy<T> source_code and modifying it_a_bit to work with Func<Task<T>>. I've_refactored the Value property to become_a FetchValueAsync method since we_can't_await_inside a property. You are_free to block the async operation_with Task.Result so_you can still use the Value property,_I_didn't want to do that because_it_may lead to problems. So it's_a_little_bit more