# Path: botoflow/core/async_root_task_context.py
# class AsyncRootTaskContext(AsyncTaskContext):
# 
#     # noinspection PyMissingConstructor
#     def __init__(self, eventloop):
#         self._setup()
#         self.eventloop = eventloop
#         self.parent = None
#         self.name = "Root"
# 
#     def update_parent(self):
#         self.exception = None
# 
# Path: botoflow/core/async_context.py
# @classmethod
# def set_async_context(cls, context):
#     if DEBUG:
#         log.debug("Setting async context: %r", context)
#     cls.thread_local.async_current_context = context


import logging
import weakref
from collections import deque
from .async_root_task_context import AsyncRootTaskContext
from .async_context import set_async_context
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.




log = logging.getLogger(__name__)

# change this to enable a ton of debug printing
DEBUG = False


class AsyncEventLoop(object):
    """
    TODO Document
    """

    def __init__(self):
        self.tasks = deque()
        self.root_context = AsyncRootTaskContext(weakref.proxy(self))

    def __enter__(self):

# Path: botoflow/core/async_root_task_context.py
# class AsyncRootTaskContext(AsyncTaskContext):
# 
#     # noinspection PyMissingConstructor
#     def __init__(self, eventloop):
#         self._setup()
#         self.eventloop = eventloop
#         self.parent = None
#         self.name = "Root"
# 
#     def update_parent(self):
#         self.exception = None
# 
# Path: botoflow/core/async_context.py
# @classmethod
# def set_async_context(cls, context):
#     if DEBUG:
#         log.debug("Setting async context: %r", context)
#     cls.thread_local.async_current_context = context


# Path: botoflow/core/async_event_loop.py
import logging
import weakref
from collections import deque
from .async_root_task_context import AsyncRootTaskContext
from .async_context import set_async_context

# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
#  http://aws.amazon.com/apache2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.




log = logging.getLogger(__name__)

# change this to enable a ton of debug printing
DEBUG = False


class AsyncEventLoop(object):
    """
    TODO Document
    """

    def __init__(self):
        self.tasks = deque()
        self.root_context = AsyncRootTaskContext(weakref.proxy(self))

    def __enter__(self):

        set_async_context(self.root_context)