Fix issue #45 with functor example.

master
Peter Hinch 2025-01-31 13:33:51 +00:00
rodzic d2929df1b4
commit d953332583
2 zmienionych plików z 4 dodań i 0 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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'