# Path: xwing/exceptions.py
# class HeartbeatFailureError(Exception):
#     pass
# 
# class ConnectionAlreadyExists(Exception):
#     pass


import asyncio
import time
import logging
from xwing.exceptions import HeartbeatFailureError, ConnectionAlreadyExists
    def __contains__(self, item):
        try:
            self.__getitem__(item)
        except KeyError:
            return False

        return True


class Connection:

    def __init__(self, loop, stream, task_pool):
        self.loop = loop
        self.stream = stream
        self.task_pool = task_pool
        self.liveness = INITIAL_HEARBEAT_LIVENESS
        self.stop_event = asyncio.Event()

    def start(self):
        self.task_pool.create_task(self.run_heartbeat_loop())

    async def run_heartbeat_loop(self, heartbeat_interval=5):
        self.start_time = time.time()

        while not self.stop_event.is_set():
            if self.liveness <= 0:
                # TODO now we need to decide how this is going
                # to work. Following this exception, we need to kill
                # this close this connection, delete the mailbox
                # and kill the process

# Path: xwing/exceptions.py
# class HeartbeatFailureError(Exception):
#     pass
# 
# class ConnectionAlreadyExists(Exception):
#     pass


# Path: xwing/network/connection.py
import asyncio
import time
import logging
from xwing.exceptions import HeartbeatFailureError, ConnectionAlreadyExists

    def __contains__(self, item):
        try:
            self.__getitem__(item)
        except KeyError:
            return False

        return True


class Connection:

    def __init__(self, loop, stream, task_pool):
        self.loop = loop
        self.stream = stream
        self.task_pool = task_pool
        self.liveness = INITIAL_HEARBEAT_LIVENESS
        self.stop_event = asyncio.Event()

    def start(self):
        self.task_pool.create_task(self.run_heartbeat_loop())

    async def run_heartbeat_loop(self, heartbeat_interval=5):
        self.start_time = time.time()

        while not self.stop_event.is_set():
            if self.liveness <= 0:
                # TODO now we need to decide how this is going
                # to work. Following this exception, we need to kill
                # this close this connection, delete the mailbox
                # and kill the process

                raise HeartbeatFailureError()