From da5de0141d1328b254425b6a70d7a2c1f3c41c2b Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Fri, 20 Mar 2015 05:21:18 +0100 Subject: [PATCH] Added post-commit callbacks to transactions. --- didex/db.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/didex/db.py b/didex/db.py index 75aee02..316fa02 100644 --- a/didex/db.py +++ b/didex/db.py @@ -64,10 +64,18 @@ class txn(object): def __init__(self, env, flags=bd.DB_TXN_WRITE_NOSYNC): self.tx = env.txn_begin(None, flags) self.done = False + self.pcommit = set() def commit(self): self.done = True self.tx.commit(0) + def run1(list): + if len(list) > 0: + try: + list[0]() + finally: + run1(list[1:]) + run1(list(self.pcommit)) def abort(self): self.done = True @@ -81,6 +89,9 @@ class txn(object): self.abort() return False + def postcommit(self, fun): + self.pcommit.add(fun) + def txnfun(envfun): def fxf(fun): def wrapper(self, *args, tx=None, **kwargs): -- 2.11.0