Skip to content

Instantly share code, notes, and snippets.

@SLAVONchick
Last active June 17, 2020 23:20
Show Gist options
  • Select an option

  • Save SLAVONchick/0de486c6586376f53d94cf5af0ce1e55 to your computer and use it in GitHub Desktop.

Select an option

Save SLAVONchick/0de486c6586376f53d94cf5af0ce1e55 to your computer and use it in GitHub Desktop.

Revisions

  1. SLAVONchick revised this gist May 15, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ReadAsyncHangs.fs
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ open FSharp.Control.Tasks
    open Pipelines.Sockets.Unofficial

    use client = new TcpClient("127.0.0.1", 9851)
    let pipe = StreamConnection.GetSuplex(client.GetStream())
    let pipe = StreamConnection.GetDuplex(client.GetStream())
    let scan = Encoding.UTF8.GetBytes "*2\r\n$4\r\nSCAN\r\n$36\r\n85AB427D-316C-4BD4-A511-6631851D212E\r\n" |> ReadOnlyMemory
    task {
    let! _ = pipe.Output.WriteAsync(scan)
  2. SLAVONchick created this gist May 15, 2020.
    21 changes: 21 additions & 0 deletions ReadAsyncHangs.fs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    open System
    open System.Net
    open FSharp.Control.Tasks
    open Pipelines.Sockets.Unofficial

    use client = new TcpClient("127.0.0.1", 9851)
    let pipe = StreamConnection.GetSuplex(client.GetStream())
    let scan = Encoding.UTF8.GetBytes "*2\r\n$4\r\nSCAN\r\n$36\r\n85AB427D-316C-4BD4-A511-6631851D212E\r\n" |> ReadOnlyMemory
    task {
    let! _ = pipe.Output.WriteAsync(scan)
    let mutable isCompleted = false
    while not isCompleted do
    let! res = pipe.Input.ReadAsync()
    for segment in res.Buffer do
    printfn "%s" <| Encoding.UTF8.GetString segment.Span
    pipe.Input.AdvanceTo(res.Buffer.Start, res.Buffer.End)
    isCompleted <- res.IsCompleted
    do! pipe.Input.CompleteAsync()
    }
    |> Async.AwaitTask
    |> Async.RunSynchronously