当前位置: 首页>>代码示例>>Python>>正文


Python Promise.fulfill方法代码示例

本文整理汇总了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
开发者ID:johansten,项目名称:stellar-py,代码行数:9,代码来源:server.py

示例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)
开发者ID:akuendig,项目名称:aplus,代码行数:29,代码来源:TestExtraFeatures.py

示例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
开发者ID:johansten,项目名称:stellar-py,代码行数:9,代码来源:server.py

示例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)
开发者ID:akuendig,项目名称:aplus,代码行数:32,代码来源:TestExtraFeatures.py

示例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")
开发者ID:akuendig,项目名称:aplus,代码行数:34,代码来源:TestSuite.py

示例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)
开发者ID:akuendig,项目名称:aplus,代码行数:33,代码来源:TestExtraFeatures.py

示例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))
开发者ID:akuendig,项目名称:aplus,代码行数:9,代码来源:TestSuite.py

示例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)
开发者ID:akuendig,项目名称:aplus,代码行数:30,代码来源:TestExtraFeatures.py

示例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)
开发者ID:alin-luminoso,项目名称:aplus,代码行数:30,代码来源:TestSuite.py

示例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")
开发者ID:LuminosoInsight,项目名称:aplus,代码行数:13,代码来源:TestExtraFeatures.py

示例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!")
开发者ID:alin-luminoso,项目名称:aplus,代码行数:13,代码来源:TestSuite.py

示例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)
开发者ID:alin-luminoso,项目名称:aplus,代码行数:13,代码来源:TestSuite.py

示例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")
开发者ID:choeger,项目名称:aplus,代码行数:14,代码来源:TestSuite.py

示例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())
开发者ID:alin-luminoso,项目名称:aplus,代码行数:14,代码来源:TestSuite.py

示例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)
开发者ID:akuendig,项目名称:aplus,代码行数:15,代码来源:TestExtraFeatures.py


注:本文中的aplus.Promise.fulfill方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。