aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-07 17:27:55 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-07 17:27:55 +0100
commit1d4b341900edffae8a04b0d91402d4c136bfb596 (patch)
tree1d24a4a0eee694d72cbf0ac730cfa5a285f39800
parentadd fsignal (diff)
downloadjoin-python-1d4b341900edffae8a04b0d91402d4c136bfb596.tar.gz
join-python-1d4b341900edffae8a04b0d91402d4c136bfb596.tar.bz2
join-python-1d4b341900edffae8a04b0d91402d4c136bfb596.tar.xz
add joinmethod
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/join.py11
-rwxr-xr-xsrc/test.py18
2 files changed, 29 insertions, 0 deletions
diff --git a/src/join.py b/src/join.py
index a873bf4..a79d32c 100644
--- a/src/join.py
+++ b/src/join.py
@@ -223,3 +223,14 @@ def concurrently(*fs):
for t in ts:
t.join()
+
+
+def joinmethod(f):
+ '''
+ Make a fragment of signal an instance method rather than a static method
+
+ @param f:(self, *..., **...)→¿R? The static method
+ @return f:(self, *..., **...)→¿R? The method made into a instance method
+ '''
+ return lambda self, *args, **kwargs : f(self, *args, **kwargs)
+
diff --git a/src/test.py b/src/test.py
index 0279f2d..a0125df 100755
--- a/src/test.py
+++ b/src/test.py
@@ -153,3 +153,21 @@ unjoining(1)
unjoining(2)
print()
+
+class C:
+ def __init__(self, value):
+ self.value = value
+
+ @joinmethod
+ @fragment
+ def f(self, v):
+ print(' %i' % (self.value + v))
+
+f1 = C(1).f
+f2 = C(2).f
+
+print('Testing @joinmethod, expecting 11,22')
+f1(10)
+f2(20)
+print()
+