             return
         }
         if let buffer = data as? ByteBuffer {
-            pendingWrites.append((buffer, promise))
-            outstanding += UInt64(buffer.readableBytes)
-            
+            pendingWrites.add(buffer: buffer, promise: promise)
         } else {
             // Only support ByteBuffer for now. 
             promise.fail(error: MessageError.unsupported)

        
        
        // Fail all pending writes and so ensure all pending promises are notified
        failPendingWrites(err: IOError(errno: EBADF, reason: "Channel closed"))
    }
    
    func registerOnEventLoop(initPipeline: (ChannelPipeline) throws ->()) {

    }

    private func flushNow() -> Bool {
        while open {
            do {
                if let written = try pendingWrites.consumeNext(body: {
                    return try self.socket.write(pointer: $0, size: $1)
                }) {
                    if !written {
                        // Could not write the next buffer completely
                        return false
                    }
                } else {
                    // we handled all writes
                    return true
                }
                
            } catch let err {
                // fail all pending writes so all promises are notified.
                failPendingWritesAndClose(err: err)
                
