Mercurial > hg > config
comparison python/example/fireonce.py @ 524:dbe9086643bf
-> example
| author | Jeff Hammel <jhammel@mozilla.com> |
|---|---|
| date | Tue, 24 Sep 2013 12:29:59 -0700 |
| parents | python/fireonce.py@8006938c33ac |
| children |
comparison
equal
deleted
inserted
replaced
| 523:d6f535ef4bdc | 524:dbe9086643bf |
|---|---|
| 1 class fireonce(object): | |
| 2 def __init__(self, func): | |
| 3 self.func = func | |
| 4 def __call__(self, *args, **kwargs): | |
| 5 if not self.func: | |
| 6 return None | |
| 7 retval = self.func(*args, **kwargs) | |
| 8 self.func = None | |
| 9 | |
| 10 @fireonce | |
| 11 def foo(x): | |
| 12 print x | |
| 13 | |
| 14 foo('bar') | |
| 15 foo('fleem') # not printed |
