# Path: swf/actors/helpers.py
# class Every(object):
#     def __init__(self, nseconds, call, *args, **kwargs):
#         """
#         Every *nseconds* call ``call(*args, **kwargs)``.
# 
#         Execute *call* in a thread.
# 
#         """
#         self.nseconds = nseconds
#         self._call = call
#         self._args = args
#         self._kwargs = kwargs
#         self._is_stopped = threading.Event()
#         self._thread = None
# 
#     def __call__(self):
#         def repeat():
#             while not self._is_stopped.wait(self.nseconds):
#                 if self._is_stopped.is_set():
#                     return
# 
#                 self._call(*self._args, **self._kwargs)
# 
#         self._thread = threading.Thread(target=repeat)
#         self._thread.daemon = True
#         self._thread.start()
#         return self
# 
#     def stop(self):
#         self._is_stopped.set()
# 
# def meanwhile(calling_this, call_that, *args, **kwargs):
#     """
# 
#     :param calling_this: function that executes in a thread or subprocess in
#     parallel of *call_that*.
#     :type calling_this: callable without argument.
# 
#     :param call_that: main function to execute
#     :type call_that: callable
# 
#     """
#     calling_this()
#     error_happened = False
#     try:
#         result = call_that(*args, **kwargs)
#     except:
#         error_happened = True
#     finally:
#         calling_this.stop()
# 
#     if error_happened:
#         raise
# 
#     return result


from .helpers import Every, meanwhile
        from functools import wraps


class heartbeat_on(object):
    def __init__(self, heartbeat, interval):
        self._heartbeat = heartbeat
        self._interval = interval

    def __call__(self, func):

        @wraps(func)
        def with_heartbeat(*args, **kwargs):
            return meanwhile(Every(self._interval,

# Path: swf/actors/helpers.py
# class Every(object):
#     def __init__(self, nseconds, call, *args, **kwargs):
#         """
#         Every *nseconds* call ``call(*args, **kwargs)``.
# 
#         Execute *call* in a thread.
# 
#         """
#         self.nseconds = nseconds
#         self._call = call
#         self._args = args
#         self._kwargs = kwargs
#         self._is_stopped = threading.Event()
#         self._thread = None
# 
#     def __call__(self):
#         def repeat():
#             while not self._is_stopped.wait(self.nseconds):
#                 if self._is_stopped.is_set():
#                     return
# 
#                 self._call(*self._args, **self._kwargs)
# 
#         self._thread = threading.Thread(target=repeat)
#         self._thread.daemon = True
#         self._thread.start()
#         return self
# 
#     def stop(self):
#         self._is_stopped.set()
# 
# def meanwhile(calling_this, call_that, *args, **kwargs):
#     """
# 
#     :param calling_this: function that executes in a thread or subprocess in
#     parallel of *call_that*.
#     :type calling_this: callable without argument.
# 
#     :param call_that: main function to execute
#     :type call_that: callable
# 
#     """
#     calling_this()
#     error_happened = False
#     try:
#         result = call_that(*args, **kwargs)
#     except:
#         error_happened = True
#     finally:
#         calling_this.stop()
# 
#     if error_happened:
#         raise
# 
#     return result


# Path: swf/actors/heartbeat.py
from .helpers import Every, meanwhile
        from functools import wraps



class heartbeat_on(object):
    def __init__(self, heartbeat, interval):
        self._heartbeat = heartbeat
        self._interval = interval

    def __call__(self, func):

        @wraps(func)
        def with_heartbeat(*args, **kwargs):
            return meanwhile(Every(self._interval,

                                   self._heartbeat, *args, **kwargs),