# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# Path: lib/utils/debounce.py
# DEFAULT_DEBOUNCE_DELAY = 0.2 # Will also be used for AsyncCommand debounce


import uuid
import time
import sublime
import json
from ..utils import Debug
from ..utils.debounce import DEFAULT_DEBOUNCE_DELAY

    def append_to_slow_queue(self):
        Debug('command', "CMD queued @SLOW: %s" % self.id)
        return self._append_to_queue('slow')

    def append_to_both_queues(self):
        return self.append_to_slow_queue() \
           and self.append_to_fast_queue()

    def _append_to_queue(self, process_type):
        if not self.project.processes.is_initialized():
            return False

        self.time_queue = time.time()
        self.time_last_bounce = self.time_queue

        if process_type == 'fast':
            self.project.processes.fast.send_async_command(self)
        elif process_type == 'slow':
            self.project.processes.slow.send_async_command(self)
        return True

    # ------------------------- call callbacks ---------------------------------- #

    def on_replaced(self, by):
        """ calls callback by using sublime.set_timeout """
        by.time_last_bounce = max(self.time_last_bounce, by.time_last_bounce)
        if self.replaced_callback is not None:
            sublime.set_timeout(lambda:self.replaced_callback(by, **self.callback_kwargs),000)


# Path: lib/utils/debug.py
# def Debug(classification, text):
#     if 'all' in print_classifications or classification in print_classifications:
#         print("ArcticTypescript: %s: %s" % (classification.ljust(8), text))
#     if classification not in possible_classifications:
#         print("ArcticTypescript: debug: got unknown debug message classification: %s. " \
#             "Consider adding this to possible_classifications" % classification)
#     sys.stdout.flush()
# 
# Path: lib/utils/debounce.py
# DEFAULT_DEBOUNCE_DELAY = 0.2 # Will also be used for AsyncCommand debounce


# Path: lib/server/AsyncCommand.py
import uuid
import time
import sublime
import json
from ..utils import Debug
from ..utils.debounce import DEFAULT_DEBOUNCE_DELAY


    def append_to_slow_queue(self):
        Debug('command', "CMD queued @SLOW: %s" % self.id)
        return self._append_to_queue('slow')

    def append_to_both_queues(self):
        return self.append_to_slow_queue() \
           and self.append_to_fast_queue()

    def _append_to_queue(self, process_type):
        if not self.project.processes.is_initialized():
            return False

        self.time_queue = time.time()
        self.time_last_bounce = self.time_queue

        if process_type == 'fast':
            self.project.processes.fast.send_async_command(self)
        elif process_type == 'slow':
            self.project.processes.slow.send_async_command(self)
        return True

    # ------------------------- call callbacks ---------------------------------- #

    def on_replaced(self, by):
        """ calls callback by using sublime.set_timeout """
        by.time_last_bounce = max(self.time_last_bounce, by.time_last_bounce)
        if self.replaced_callback is not None:
            sublime.set_timeout(lambda:self.replaced_callback(by, **self.callback_kwargs),000)


        Debug('command+', "CMD replaced after %fs [ %s ]" % (time.time() - self.time_queue, self.id))