##// END OF EJS Templates
transaction: allow registering a finalization callback...
Pierre-Yves David -
r23204:10beda5b default
parent child Browse files
Show More
@@ -105,6 +105,8 class transaction(object):
105 self._pendingcallback = {}
105 self._pendingcallback = {}
106 # True is any pending data have been written ever
106 # True is any pending data have been written ever
107 self._anypending = False
107 self._anypending = False
108 # holds callback to call when writing the transaction
109 self._finalizecallback = {}
108
110
109 def __del__(self):
111 def __del__(self):
110 if self.journal:
112 if self.journal:
@@ -288,10 +290,22 class transaction(object):
288 return self._anypending
290 return self._anypending
289
291
290 @active
292 @active
293 def addfinalize(self, category, callback):
294 """add a callback to be called when the transaction is closed
295
296 Category is a unique identifier to allow overwriting old callbacks with
297 newer callbacks.
298 """
299 self._finalizecallback[category] = callback
300
301 @active
291 def close(self):
302 def close(self):
292 '''commit the transaction'''
303 '''commit the transaction'''
293 if self.count == 1 and self.onclose is not None:
304 if self.count == 1 and self.onclose is not None:
294 self._generatefiles()
305 self._generatefiles()
306 categories = sorted(self._finalizecallback)
307 for cat in categories:
308 self._finalizecallback[cat]()
295 self.onclose()
309 self.onclose()
296
310
297 self.count -= 1
311 self.count -= 1
General Comments 0
You need to be logged in to leave comments. Login now