.net - SynchronizationLockException in AsyncSeq.cache -


when call asyncseq.cache synchronizationlockexception @ line calling monitor.exit(iref). can problem is?

please note i'm using asyncseq.cache in project without such problems.

thanks!

see below test code:

[<entrypoint>] let main argv =      let asyncop x =         async {             do! async.sleep x             return x         }      let chooser x = if x > 1000 x else none      let execute (input : asyncseq<int>) =         async {             printfn "first result... expect 3s sleep"             let! r1 = asyncseq.trypick chooser input             printfn "computing second result. expect no sleep"             let! r2 = asyncseq.trypick chooser input             printfn "done"             return (r1,r2)         }      printfn "starting..."      let v =         [1000;2000;3000;300000]         |> asyncseq.ofseq         |> asyncseq.mapasync asyncop         |> asyncseq.cache         |> execute         |> async.runsynchronously       printfn "results: = %a" v     system.console.readkey() |> ignore     0 

see below code asyncseq.cache reference

let cache (source : asyncseq<'t>) =      let cache = resizearray<_>()     asyncseq {         use ie = source.getenumerator()          let iref = ref 0         let fin = ref false         while not fin.value             let = iref.value             lock(iref)             let locktaken = ref false             try                  system.threading.monitor.enter(iref, locktaken);                 if >= cache.count                      let! move = ie.movenext()                     cache.add(move)                     iref := + 1                             if locktaken.value                     system.threading.monitor.exit(iref)             match cache.[i]              | v -> yield v             | none -> fin := true } 


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -