F#异步并让!混乱

时间:2016-07-12 15:13:07

标签: asynchronous f#

我对

感到困惑
let decode buffer = Encoding.UTF8.GetString(buffer)

行,那里发生了什么?

缓冲区在异步中声明,还是闭包?

https://github.com/sebfia/OffLog/blob/master/Shared/FeedStorage.fs#L22

 let thaw<'T> path =
     let decode buffer = Encoding.UTF8.GetString(buffer)

     async {
         try
             match File.Exists(path) with

             | false -> return None

             | true ->
                 use fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None)
                 let! buffer = fs.AsyncRead(fs.Length |> Convert.ToInt32)
                 let str = decode buffer
                 System.Diagnostics.Debug.WriteLine(str)

                 let bla = JsonConvert.DeserializeObject<'T>(str)

                 System.Diagnostics.Debug.WriteLine(typeof<'T>.GetType().FullName)
                 return bla |> Some

         with | e -> System.Diagnostics.Debug.WriteLine(e.ToString()); return None

     }

0 个答案:

没有答案