Mercurial > hg > config
comparison python/fireonce.py @ 164:8006938c33ac
add fireonce decorator example
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Mon, 22 Aug 2011 13:38:28 -0700 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
163:eb0049718001 | 164:8006938c33ac |
---|---|
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 |