Skip to content

CircularQueueAgent blocks all readers when request to dequeue is larger than maxLength #28

@sgoguen

Description

@sgoguen

The following code reproduces the issues:

#r "./bin/Debug/FSharpx.Async.dll"

//  Let's use a curcular queue agent to distribute work
let queue = FSharpx.Control.CircularQueueAgent<string>(5)

//  Let's create a simple reader process
let reader(name, taking,delay) = 
  async {
    printfn "Starting Reader"
    try
      while true do
        let! values = queue.AsyncDequeue(taking)
        for value in values do
          printfn "%s: Reading %s" name value
        do! Async.Sleep(delay)
    finally
      printfn "Stopped Reader"
  } |> Async.Start

//  And a function to continually add items
let addItems(x) = 
  async {
    for x in [1..x] do
      do! queue.AsyncEnqueue([|sprintf "Hi %i" x |])
  } |> Async.Start

//  This works fine
addItems(500)
System.Threading.Thread.Sleep(2000)
reader("Hao", 1, 100)
System.Threading.Thread.Sleep(2000)
reader("Bob", 5, 1000)
System.Threading.Thread.Sleep(2000)
//  This is where everything stops
reader("Xen", 10, 1000)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions