本文整理汇总了Python中aplus.Promise.then方法的典型用法代码示例。如果您正苦于以下问题:Python Promise.then方法的具体用法?Python Promise.then怎么用?Python Promise.then使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aplus.Promise
的用法示例。
在下文中一共展示了Promise.then方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_3_2_6_3_when_fulfilled
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_3_when_fulfilled():
"""
Testing return of pending promises to make
sure they are properly chained.
This covers the case where the root promise
is fulfilled after the chaining is defined.
"""
p1 = Promise()
pending = Promise()
pf = p1.then(lambda r: pending)
assert pending.isPending()
assert pf.isPending()
p1.fulfill(10)
pending.fulfill(5)
assert pending.isFulfilled()
assert_equals(5, pending.value)
assert pf.isFulfilled()
assert_equals(5, pf.value)
p2 = Promise()
bad = Promise()
pr = p2.then(lambda r: bad)
assert bad.isPending()
assert pr.isPending()
p2.fulfill(10)
bad.reject("Error")
assert bad.isRejected()
assert_equals("Error", bad.reason)
assert pr.isRejected()
assert_equals("Error", pr.reason)
示例2: test_3_2_6_3_when_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_3_when_rejected():
"""
Testing return of pending promises to make
sure they are properly chained.
This covers the case where the root promise
is rejected after the chaining is defined.
"""
p1 = Promise()
pending = Promise()
pr = p1.then(None, lambda r: pending)
assert pending.isPending
assert pr.isPending
p1.reject(Exception("Error"))
pending.fulfill(10)
assert pending.isFulfilled
assert_equals(10, pending.value)
assert pr.isFulfilled
assert_equals(10, pr.value)
p2 = Promise()
bad = Promise()
pr = p2.then(None, lambda r: bad)
assert bad.isPending
assert pr.isPending
p2.reject(Exception("Error"))
bad.reject(Exception("Assertion"))
assert bad.isRejected
assert_exception(bad.reason, Exception, "Assertion")
assert pr.isRejected
assert_exception(pr.reason, Exception, "Assertion")
示例3: test_3_2_6_3_if_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_3_if_rejected():
"""
Testing return of pending promises to make
sure they are properly chained.
This covers the case where the root promise
is rejected before the chaining is defined.
"""
p1 = Promise()
p1.reject("Error")
pending = Promise()
pending.fulfill(10)
pr = p1.then(None, lambda r: pending)
assert pending.isFulfilled()
assert_equals(10, pending.value)
assert pr.isFulfilled()
assert_equals(10, pr.value)
p2 = Promise()
p2.reject("Error")
bad = Promise()
bad.reject("Assertion")
pr = p2.then(None, lambda r: bad)
assert bad.isRejected()
assert_equals("Assertion", bad.reason)
assert pr.isRejected()
assert_equals("Assertion", pr.reason)
示例4: test_3_2_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_1():
"""
Test that the arguments to 'then' are optional.
"""
p1 = Promise()
p2 = p1.then()
p3 = Promise()
p4 = p3.then()
p1.fulfill(5)
p3.reject("How dare you!")
示例5: testNonFunction
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def testNonFunction(nonFunction):
def foo(k, r):
results[k] = r
p1 = Promise()
p2 = p1.then(lambda r: foo(str(nonFunction), r), nonFunction)
p1.fulfill("Error: " + str(nonFunction))
示例6: test_3_2_6_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_1():
"""
Promises returned by then must be fulfilled when the promise
they are chained from is fulfilled IF the fulfillment value
is not a promise.
"""
p1 = Promise()
pf = p1.then(lambda v: v*v)
p1.fulfill(5)
assert_equals(pf.value, 25)
p2 = Promise()
pr = p2.then(None, lambda r: 5)
p2.reject("Error")
assert_equals(5, pr.value)
示例7: test_3_2_6_2_if
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_2_if():
"""
Promises returned by then must be rejected when any of their
callbacks throw an exception.
"""
def fail(v):
raise AssertionError("Exception Message")
p1 = Promise()
p1.fulfill(5)
pf = p1.then(fail)
assert pf.isRejected()
assert_equals("Exception Message", pf.reason)
p2 = Promise()
p2.reject("Error")
pr = p2.then(None, fail)
assert pr.isRejected()
assert_equals("Exception Message", pr.reason)
示例8: test_3_2_6_4_fulfilled
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_4_fulfilled():
"""
Handles the case where the arguments to then
are values, not functions or promises.
"""
p1 = Promise()
p1.fulfill(10)
p2 = p1.then(5)
assert_equals(10, p1.value)
assert p2.isFulfilled()
assert_equals(10, p2.value)
示例9: test_3_2_6_5_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_5_rejected():
"""
Handles the case where the arguments to then
are values, not functions or promises.
"""
p1 = Promise()
p1.reject("Error")
p2 = p1.then(None, 5)
assert_equals("Error", p1.reason)
assert p2.isRejected()
assert_equals("Error", p2.reason)
示例10: test_3_2_6_5_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_5_rejected():
"""
Handles the case where the arguments to then
are values, not functions or promises.
"""
p1 = Promise()
p1.reject(Exception("Error"))
p2 = p1.then(None, 5)
assert_exception(p1.reason, Exception, "Error")
assert p2.isRejected
assert_exception(p2.reason, Exception, "Error")
示例11: test_3_2_3_3
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_3_3():
"""
Make sure rejected callback never called if promise is fulfilled
"""
cf = Counter()
cr = Counter()
p1 = Promise()
p2 = p1.then(lambda v: cf.tick(), lambda r: cr.tick())
p1.fulfill(5)
assert_equals(0, cr.value())
assert_equals(1, cf.value())
示例12: test_3_2_6_1_literally
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_6_1_literally():
"""
If _either_ onFulfilled or onRejected returns a value
that is not a promise, promise2 must be fulfilled with that value
"""
def _raise(e):
raise e
p1 = Promise()
pf = p1.then(lambda v : _raise(Exception("Error")), lambda x : "catched")
p1.fulfill(5)
assert_equals(pf.value, "catched")
示例13: transaction_fields_completed_promise
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def transaction_fields_completed_promise(tx_json):
p = Promise()
if 'Flags' in tx_json:
tx_json['Flags'] |= tfFullyCanonicalSig
else:
tx_json['Flags'] = 0
tx_json['Fee'] = stellar.get_fee()
if 'Sequence' in tx_json:
p.fulfill(tx_json)
else:
def inner(res):
tx_json['Sequence'] = res['Sequence']
p.fulfill(tx_json)
p = stellar.get_account_info_promise(tx_json['Account'])
p.then(inner)
return p
示例14: test_3_2_2_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_2_1():
"""
The first argument to 'then' must be called when a promise is
fulfilled.
"""
c = Counter()
def check(v, c):
assert_equals(v, 5)
c.tick()
p1 = Promise()
p2 = p1.then(lambda v: check(v, c))
p1.fulfill(5)
assert_equals(1, c.value())
示例15: test_3_2_3_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import then [as 别名]
def test_3_2_3_1():
"""
The second argument to 'then' must be called when a promise is
rejected.
"""
c = Counter()
def check(r, c):
assert_equals(r, "Error")
c.tick()
p1 = Promise()
p2 = p1.then(None, lambda r: check(r, c))
p1.reject("Error")
assert_equals(1, c.value())