<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 async def wait_event(self, event, *, timeout=None):
 """ Waits for a custom event to occur. Timeouts still apply. Unless you're certain that your code will run fast enough, generally you should get a "handle" of this special coroutine before acting. Generally, you should do this: This way your event can be registered before acting, since the response may arrive before your event was registered. It depends on your use case since this also means the event can arrive before you send a previous action. """

        start_time = time.time()
        if isinstance(event, type):
            event = event()

        await event.resolve(self._client)

        counter = Conversation._custom_counter
        Conversation._custom_counter += 1

        future = asyncio.Future(loop=self._client.loop)

        # We need the `async def` here because we want to block on the future
        # from `_get_result` by using `await` on it. If we returned the future
        # immediately we would `del` from `_custom` too early.

        async def result():
            try:
                return await self._get_result(future, start_time, timeout)
            finally:
                del self._custom[counter]

        self._custom[counter] = (event, future)
        return await result()