# Path: marathoner/utils/async_reader.py
# class AsyncReader(threading.Thread):
#     '''Asynchronously read lines from the stream and call the callback function
#     for each line.
#     '''
#     def __init__(self, stream, callback):
#         super(AsyncReader, self).__init__()
#         self.stream = stream
#         self.callback = callback
# 
#     def run(self):
#         while True:
#             try:
#                 line = self.stream.readline()
#             except:
#                 return
#             if not line:
#                 return
#             if self.callback(line):
#                 return


from functools import partial
from marathoner.utils.async_reader import AsyncReader



class Communicator(object):
    def communicate(self, visualizer, solution, visualizer_cb, solution_cb):
        visualizer_input_reader = AsyncReader(visualizer, partial(visualizer_cb, flush=True))
        visualizer_input_reader.setDaemon(True)
        visualizer_input_reader.start()

# Path: marathoner/utils/async_reader.py
# class AsyncReader(threading.Thread):
#     '''Asynchronously read lines from the stream and call the callback function
#     for each line.
#     '''
#     def __init__(self, stream, callback):
#         super(AsyncReader, self).__init__()
#         self.stream = stream
#         self.callback = callback
# 
#     def run(self):
#         while True:
#             try:
#                 line = self.stream.readline()
#             except:
#                 return
#             if not line:
#                 return
#             if self.callback(line):
#                 return


# Path: marathoner/communicators/general_communicator.py
from functools import partial
from marathoner.utils.async_reader import AsyncReader




class Communicator(object):
    def communicate(self, visualizer, solution, visualizer_cb, solution_cb):
        visualizer_input_reader = AsyncReader(visualizer, partial(visualizer_cb, flush=True))
        visualizer_input_reader.setDaemon(True)
        visualizer_input_reader.start()

        solution_output_reader = AsyncReader(solution, partial(solution_cb, flush=False))