     public final func flush0(promise: EventLoopPromise<Void>?) {
         assert(eventLoop.inEventLoop)
 
-        if closed {
+        guard !self.closed else {
             promise?.fail(error: ChannelError.ioOnClosedChannel)
             return
         }
 
         self.markFlushPoint(promise: promise)
 
-        if !isWritePending() && !flushNow() && !closed {
+        if !isWritePending() && flushNow() == .register {
             registerForWritable()
         }
     }

        assert(!closed)

        finishConnect()  // If we were connecting, that has finished.
        if flushNow() {
            // Everything was written or connect was complete
            finishWritable()
        }

class BaseSocketChannel<T : BaseSocket> : SelectableChannel, ChannelCore {
    typealias SelectableType = T

    /// Indicates if a selectable should registered or not for IO notifications.
    enum IONotificationState {
        /// We should be registered for IO notifications.
        case register

        /// We should not be registered for IO notifications.
        case unregister
    }

    // MARK: Methods to override in subclasses.

    /// `true` if the whole `Channel` is closed and so no more IO operation can be done.
