Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve outer promises getting blocked waiting on inner promises to complete. #34

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions promise/async_.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Based on https://github.com/petkaantonov/bluebird/blob/master/src/promise.js
import collections
from threading import Thread


class Async(object):
Expand Down Expand Up @@ -67,10 +68,10 @@ def drain_queue(self, queue):
from .promise import Promise
while queue:
fn = queue.popleft()
if (isinstance(fn, Promise)):
if isinstance(fn, Promise):
fn._settle_promises()
continue
fn()
Thread(target=fn).start()

def drain_queues(self):
assert self.is_tick_used
Expand Down
15 changes: 13 additions & 2 deletions tests/test_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,20 @@ def test_promises_promisify_still_works_but_deprecated_for_non_callables():
# values = Promise.resolve([1, None, 2])
# def on_error(error):
# error

# def executor(resolve, reject):
# resolve(Promise.resolve(values).then(lambda values: Promise.all([Promise.resolve(values[0])]).catch(on_error)))

# p = Promise(executor)
# assert p.get(.1) == 2


def test_get_after_get_in_promise():
expected_value = "ok"

def do(_):
def then_fn(y):
return y
completed_promise_value = Promise.resolve(expected_value).then(then_fn).get()
return completed_promise_value

p = Promise.resolve(None).then(do)
assert p.get() == expected_value