diff --git a/functor_singleton/README.md b/functor_singleton/README.md index d801753..cba7c80 100644 --- a/functor_singleton/README.md +++ b/functor_singleton/README.md @@ -78,10 +78,13 @@ class MyFunctor: def __call__(self, arg): print('In __call__', arg + self.state) + return self MyFunctor(42) # prints 'In __init__ 42' MyFunctor(5) # 'In __call__ 47' ``` +In both test cases the object returned is the functor instance. + A use case is in asynchronous programming. The constructor launches a continuously running task. Subsequent calls alter the behaviour of that task. The following simple example has the task waiting for a period which can be diff --git a/functor_singleton/examples.py b/functor_singleton/examples.py index f8c986b..36d0111 100644 --- a/functor_singleton/examples.py +++ b/functor_singleton/examples.py @@ -39,6 +39,7 @@ class MyFunctor: def __call__(self, arg): print('In __call__', arg + self.state) + return self MyFunctor(42) # prints 'In __init__ 42' MyFunctor(5) # 'In __call__ 47'