         return promise.futureResult
     }
 
-    public func run(initPipeline: (ChannelPipeline) throws -> ()) throws {
-        thread = Thread.current
-        
-        defer {
-            // Reset the thread once we exit this method.
-            thread = nil
-        }
-        
+    func run(initPipeline: (ChannelPipeline) throws -> ()) throws {
+        assert(inEventLoop)
         while true {
             // Block until there are events to handle
             if let events = try selector.awaitReady() {

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



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

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