     }
     
     public func execute(task: @escaping () -> ()) {
+        assert(inEventLoop)
         tasks.append(task)
     }
 


// TODO: Implement scheduling tasks in the future (a.k.a ScheduledExecutoreService
public class EventLoop {
    let selector: Sockets.Selector
    var tasks: [() -> ()]
    var thread: Thread?

    init() throws{
        self.selector = try Sockets.Selector()
        self.tasks = Array()
    }
    
    func register(server: ServerSocket) throws {
        try self.selector.register(selectable: server)
    }
    
    func register(channel: Channel) throws {
        try selector.register(selectable: channel.socket, interested: channel.interestedEvent, attachment: channel)
    }
    
    func deregister(channel: Channel) throws {
        try selector.deregister(selectable: channel.socket)
    }
    
    func reregister(channel: Channel) throws {
        try selector.reregister(selectable: channel.socket, interested: channel.interestedEvent)
    }
    

        return promise.futureResult
    }

    func run(initPipeline: (ChannelPipeline) throws -> ()) throws {
        assert(inEventLoop)
        while true {
            // Block until there are events to handle
            if let events = try selector.awaitReady() {
