       {
         dispatch_semaphore_signal(rs)
       }
-      else if head+capacity > tail || closed, let ws = writerQueue.dequeue()
+      else if head+capacity > nextput || closed, let ws = writerQueue.dequeue()
       {
         dispatch_semaphore_signal(ws)
       }

//

import Dispatch
import Foundation.NSThread

/**
  A channel that uses a queue of semaphores for scheduling.

        {
          dispatch_semaphore_signal(rs)
        }
        else if self.head+self.capacity > self.nextput || self.closed, let ws = self.writerQueue.dequeue()
        {
          dispatch_semaphore_signal(ws)
        }
