Skip to content

Commit

Permalink
Fixed lint and mypy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Mar 5, 2017
1 parent b627500 commit a63564f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
13 changes: 6 additions & 7 deletions promise/async_.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from threading import Timer, Thread
# from threading import Timer, Thread

from .compat import Queue
from .context import Context
# from .context import Context

# Based on https://github.com/petkaantonov/bluebird/blob/master/src/async.js


class Scheduler(object):

def call(self, fn):

def call(self, fn):
# thread = Thread(target=fn)
# thread = Timer(0.001, fn)
# fn = thread.start
Expand All @@ -18,7 +17,7 @@ def call(self, fn):
# if not c:
fn()
# else:
# c.on_exit(fn)
# c.on_exit(fn)
except:
pass
# thread = Thread(target=fn)
Expand Down Expand Up @@ -72,8 +71,8 @@ def invoke_later(self, fn, context):
else:
self.schedule.call_later(0.1, fn)

def invoke(self, fn, context, with_trampoline=None):
if with_trampoline or (self.trampoline_enabled and with_trampoline != False):
def invoke(self, fn, context):
if self.trampoline_enabled:
self._async_invoke(fn, context)
else:
self.schedule.call(
Expand Down
17 changes: 13 additions & 4 deletions promise/context.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
context_stack = []

from typing import Callable


class Context(object):

__slots__ = ('_parent', '_exited', '_exit_fns')

def __init__(self):
self._parent = self.peek_context()
if self._parent:
self._parent.on_exit(self._exit)
self._exited = False
self._exit_fns = []
self._exit_fns = [] # type: List[Callable]

def push_context(self):
# if self._trace:
Expand All @@ -20,9 +25,13 @@ def __enter__(self):

def __exit__(self, type, value, traceback):
assert not self._exited, "Can't exit a Context twice"
self.pop_context()
self._exited = True
self.drain_queue()
self._exit()

def _exit(self):
if not self._exited:
self._exited = True
self.pop_context()
self.drain_queue()

def drain_queue(self):
exit_fns = self._exit_fns
Expand Down
2 changes: 1 addition & 1 deletion promise/promise.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(self, executor=None):
self._rejection_handler0 = None # type: Union[Callable, partial]
self._promise0 = None # type: Promise
self._future = None # type: Future
self._event_instance = None
self._event_instance = None # type: Event
self._trace = Context.peek_context()

self._is_waiting = False
Expand Down
2 changes: 1 addition & 1 deletion promise/promise_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def _iterate(self, values):
Promise = self._promise_class
is_resolved = False
self._length = len(values)
self._values = [ None ] * self._length
self._values = [None] * self._length

result = self.promise

Expand Down

0 comments on commit a63564f

Please sign in to comment.