Skip to content

Commit

Permalink
Simpler context manager implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajdavis committed Jan 31, 2015
1 parent 7edcca2 commit e081117
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions toro/locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import contextlib
import collections

from tornado import ioloop
from tornado import gen, ioloop
from tornado.concurrent import Future

from . import _util
Expand All @@ -25,15 +25,9 @@ class _ContextManagerFuture(Future):
"""
def __init__(self, wrapped, exit_callback):
super(_ContextManagerFuture, self).__init__()
wrapped.add_done_callback(self._done_callback)
gen.chain_future(wrapped, self)
self.exit_callback = exit_callback

def _done_callback(self, wrapped):
if wrapped.exception():
self.set_exception(wrapped.exception())
else:
self.set_result(wrapped.result())

def result(self):
if self.exception():
raise self.exception()
Expand Down

0 comments on commit e081117

Please sign in to comment.