本文整理汇总了Python中aplus.Promise.fulfill方法的典型用法代码示例。如果您正苦于以下问题:Python Promise.fulfill方法的具体用法?Python Promise.fulfill怎么用?Python Promise.fulfill使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aplus.Promise
的用法示例。
在下文中一共展示了Promise.fulfill方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _handle_server_status
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def _handle_server_status(self, msg_json):
self.fee.set_load_scale(msg_json)
p = Promise()
p.fulfill(self.fee.calculate_fee())
self.fee_promise = p
return True
示例2: test_list_promise_if
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def test_list_promise_if():
p1 = Promise()
p2 = Promise()
pd1 = listPromise([p1, p2])
pd2 = listPromise([p1])
pd3 = listPromise([])
assert p1.isPending
assert p2.isPending
assert pd1.isPending
assert pd2.isPending
assert pd3.isFulfilled
p1.fulfill(5)
assert p1.isFulfilled
assert p2.isPending
assert pd1.isPending
assert pd2.isFulfilled
p2.fulfill(10)
assert p1.isFulfilled
assert p2.isFulfilled
assert pd1.isFulfilled
assert pd2.isFulfilled
assert_equals(5, p1.value)
assert_equals(10, p2.value)
assert_equals(5, pd1.value[0])
assert_equals(5, pd2.value[0])
assert_equals(10, pd1.value[1])
assert_equals([], pd3.value)
示例3: _handle_ledger_closed
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def _handle_ledger_closed(self, msg_json):
self.fee.set_fee_scale(msg_json)
p = Promise()
p.fulfill(self.fee.calculate_fee())
self.fee_promise = p
return True
示例4: test_then_all
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def test_then_all():
p = Promise()
handlers = [
((lambda x: x * x), (lambda r: 1)),
{'success': (lambda x: x + x), 'failure': (lambda r: 2)},
]
results = p.then_all() + p.then_all(((lambda x: x * x), (lambda r: 1))) + p.then_all(handlers)
p.fulfill(4)
assert_equals(results[0].value, 16)
assert_equals(results[1].value, 16)
assert_equals(results[2].value, 8)
p = Promise()
handlers = [
((lambda x: x * x), (lambda r: 1)),
{'success': (lambda x: x + x), 'failure': (lambda r: 2)},
]
results = p.then_all() + p.then_all(((lambda x: x * x), (lambda r: 1))) + p.then_all(handlers)
p.reject(Exception())
assert_equals(results[0].value, 1)
assert_equals(results[1].value, 1)
assert_equals(results[2].value, 2)
示例5: test_3_2_6_3_when_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [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")
示例6: test_done_all
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def test_done_all():
counter = [0]
def inc(_):
counter[0] += 1
def dec(_):
counter[0] -= 1
p = Promise()
p.done_all()
p.done_all((inc, dec))
p.done_all([
(inc, dec),
(inc, dec),
{'success': inc, 'failure': dec},
])
p.fulfill(4)
assert_equals(counter[0], 4)
p = Promise()
p.done_all()
p.done_all((inc, dec))
p.done_all([
(inc, dec),
{'success': inc, 'failure': dec},
])
p.reject(Exception())
assert_equals(counter[0], 1)
示例7: testNonFunction
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [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))
示例8: test_dict_promise_when
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def test_dict_promise_when():
p1 = Promise()
p2 = Promise()
d = {"a": p1, "b": p2}
pd1 = dictPromise(d)
pd2 = dictPromise({"a": p1})
pd3 = dictPromise({})
assert p1.isPending
assert p2.isPending
assert pd1.isPending
assert pd2.isPending
assert pd3.isFulfilled
p1.fulfill(5)
assert p1.isFulfilled
assert p2.isPending
assert pd1.isPending
assert pd2.isFulfilled
p2.fulfill(10)
assert p1.isFulfilled
assert p2.isFulfilled
assert pd1.isFulfilled
assert pd2.isFulfilled
assert_equals(5, p1.value)
assert_equals(10, p2.value)
assert_equals(5, pd1.value["a"])
assert_equals(5, pd2.value["a"])
assert_equals(10, pd1.value["b"])
assert_equals({}, pd3.value)
示例9: test_3_2_6_3_if_rejected
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [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)
示例10: test_exceptions
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def test_exceptions():
def throws(v):
assert False
p1 = Promise()
p1.addCallback(throws)
p1.fulfill(5)
p2 = Promise()
p2.addErrback(throws)
p2.reject("Error")
示例11: test_3_2_1
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [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!")
示例12: test_3_2_6_4_fulfilled
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [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)
示例13: test_3_2_6_1_literally
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [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")
示例14: test_3_2_3_3
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [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())
示例15: test_exceptions
# 需要导入模块: from aplus import Promise [as 别名]
# 或者: from aplus.Promise import fulfill [as 别名]
def test_exceptions():
def throws(v):
assert False
p1 = Promise()
p1.addCallback(throws)
p1.fulfill(5)
p2 = Promise()
p2.addErrback(throws)
p2.reject(Exception())
assert_raises(Exception, p2.get)