# Path: guild/actor.py
# class Actor(ActorMixin, _Thread):
#     daemon = True
# 
#     def __init__(self):
#         self.killflag = False
#         super(Actor, self).__init__()
# 
#     def run(self):
#         self.process_start()
#         self.process()
#         try:
#             gen = self.main
#         except AttributeError:
#             try:
#                 gen = self.gen_process
#             except AttributeError:
#                 gen = None
# 
#         if gen:
#             # NB next line looks at the code object, and checks a flag
#             if inspect.isgeneratorfunction(gen):
#                 g = gen()
#             else:
#                 function_name = gen.__self__.__class__.__name__ +"."+gen.__name__
#                 source_ref = "(%s, line: %d)" % (gen.__func__.__code__.co_filename, gen.__func__.__code__.co_firstlineno)
#                 warning = "Function %s %s must be a generator" % (function_name, source_ref)
#                 raise ValueError(warning)
#         else:
#             g = None
# 
#         while not self.killflag:
# 
#             while (self.F_inbound or self.inbound or self.core):
#                 self._actor_do_queued()
# 
#             if not self._actor_do_queued():
#                 if g is None:
#                     time.sleep(0.01)
#             if g:
#                 try:
#                     next(g)
#                 except StopIteration:
#                     # Print("Generator Exited")
#                     self.stop()
#                     g = None
#         self.onStop()
#         if g:
#             try:
#                 g.throw(StopIteration)
#             except StopIteration:
#                 pass
# 
#     def stop(self):
#         self.killflag = True
# 
# def actor_method(method):
#     return ("ACTORMETHOD", method)
# 
# def actor_function(timeout=None):
#     # Just used as "@actor_function -- ie the common case"
#     if callable(timeout):
#         return actor_function(None)(timeout)
# 
#     def dec(fn):
#         return ("ACTORFUNCTION", fn, timeout)
# 
#     return dec
# 
# class ActorNotStartedException(Exception): #NOTE: Overview documented
#     pass


from behave import given, when, then, step
from guild.actor import Actor, actor_method, actor_function, ActorNotStartedException
from hamcrest import *
import time

class UserDefinedException(Exception):
    pass

class SimpleActor(Actor):
    def __init__(self, a, b, c):
        super(SimpleActor, self).__init__()
        self.a = a
        self.b = b
        self.c = c
    #
    def __repr__(self):
        return "SimpleActor"+str((self.a,self.b,self.c))
    def geta(self): return self.a
    def getb(self): return self.b
    def getc(self): return self.c
    def seta(self,v): self.a = v
    def setb(self,v): self.b = v
    def setc(self,v): self.c = v
    #
    @actor_function(0.01)
    def combine(self):
        return (self.a, self.b, self.c)
    #
    @actor_method
    def increment(self):
        self.a += 1
        self.b += 1
        self.c += 1
    #

# Path: guild/actor.py
# class Actor(ActorMixin, _Thread):
#     daemon = True
# 
#     def __init__(self):
#         self.killflag = False
#         super(Actor, self).__init__()
# 
#     def run(self):
#         self.process_start()
#         self.process()
#         try:
#             gen = self.main
#         except AttributeError:
#             try:
#                 gen = self.gen_process
#             except AttributeError:
#                 gen = None
# 
#         if gen:
#             # NB next line looks at the code object, and checks a flag
#             if inspect.isgeneratorfunction(gen):
#                 g = gen()
#             else:
#                 function_name = gen.__self__.__class__.__name__ +"."+gen.__name__
#                 source_ref = "(%s, line: %d)" % (gen.__func__.__code__.co_filename, gen.__func__.__code__.co_firstlineno)
#                 warning = "Function %s %s must be a generator" % (function_name, source_ref)
#                 raise ValueError(warning)
#         else:
#             g = None
# 
#         while not self.killflag:
# 
#             while (self.F_inbound or self.inbound or self.core):
#                 self._actor_do_queued()
# 
#             if not self._actor_do_queued():
#                 if g is None:
#                     time.sleep(0.01)
#             if g:
#                 try:
#                     next(g)
#                 except StopIteration:
#                     # Print("Generator Exited")
#                     self.stop()
#                     g = None
#         self.onStop()
#         if g:
#             try:
#                 g.throw(StopIteration)
#             except StopIteration:
#                 pass
# 
#     def stop(self):
#         self.killflag = True
# 
# def actor_method(method):
#     return ("ACTORMETHOD", method)
# 
# def actor_function(timeout=None):
#     # Just used as "@actor_function -- ie the common case"
#     if callable(timeout):
#         return actor_function(None)(timeout)
# 
#     def dec(fn):
#         return ("ACTORFUNCTION", fn, timeout)
# 
#     return dec
# 
# class ActorNotStartedException(Exception): #NOTE: Overview documented
#     pass


# Path: features/steps/actor_feature_steps.py
from behave import given, when, then, step
from guild.actor import Actor, actor_method, actor_function, ActorNotStartedException
from hamcrest import *
import time


class UserDefinedException(Exception):
    pass

class SimpleActor(Actor):
    def __init__(self, a, b, c):
        super(SimpleActor, self).__init__()
        self.a = a
        self.b = b
        self.c = c
    #
    def __repr__(self):
        return "SimpleActor"+str((self.a,self.b,self.c))
    def geta(self): return self.a
    def getb(self): return self.b
    def getc(self): return self.c
    def seta(self,v): self.a = v
    def setb(self,v): self.b = v
    def setc(self,v): self.c = v
    #
    @actor_function(0.01)
    def combine(self):
        return (self.a, self.b, self.c)
    #
    @actor_method
    def increment(self):
        self.a += 1
        self.b += 1
        self.c += 1
    #

    @actor_function(0.01)