'If the event handler returns a value, the event is removed from the
reactor and the handler\'s C{connectionLost} method is called in the I/O
thread.'

def test_disconnectOnReturnValue(self):

    reactorThreadID = getThreadID()
    reactor = self.buildReactor()
    event = win32event.CreateEvent(None, False, False, None)
    result = []
    finished = Deferred()
    finished.addBoth(result.append)
    finished.addBoth((lambda ignored: reactor.stop()))
    listener = Listener(finished)
    reactor.addEvent(event, listener, 'returnValueOccurred')
    reactor.callWhenRunning(win32event.SetEvent, event)
    self.runReactor(reactor)
    self.assertIsInstance(result[0], Failure)
    result[0].trap(EnvironmentError)
    self.assertEqual(reactorThreadID, listener.connLostThreadID)
