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


Python Future.set_result方法代码示例

本文整理汇总了Python中hazelcast.future.Future.set_result方法的典型用法代码示例。如果您正苦于以下问题:Python Future.set_result方法的具体用法?Python Future.set_result怎么用?Python Future.set_result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hazelcast.future.Future的用法示例。


在下文中一共展示了Future.set_result方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Invocation

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
class Invocation(object):
    sent_connection = None
    timer = None

    def __init__(self, request, partition_id=-1, address=None, connection=None, timeout=INVOCATION_TIMEOUT):
        self._event = threading.Event()
        self.timeout = timeout + time.time()
        self.address = address
        self.connection = connection
        self.partition_id = partition_id
        self.request = request
        self.future = Future()

    def has_connection(self):
        return self.connection is not None

    def has_partition_id(self):
        return self.partition_id >= 0

    def has_address(self):
        return self.address is not None

    def set_response(self, response):
        if self.timer:
            self.timer.cancel()
        self.future.set_result(response)

    def set_exception(self, exception, traceback=None):
        if self.timer:
            self.timer.cancel()
        self.future.set_exception(exception, traceback)

    def on_timeout(self):
        self.set_exception(TimeoutError("Request timed out after %d seconds." % INVOCATION_TIMEOUT))
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:36,代码来源:invocation.py

示例2: test_callback_throws_exception

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_callback_throws_exception(self):
        f = Future()

        def invalid_func():
            raise RuntimeError("error!")

        f.add_done_callback(invalid_func)
        f.set_result("done")  # should not throw exception
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:10,代码来源:future_test.py

示例3: test_running

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_running(self):
        f = Future()

        self.assertTrue(f.running())

        f.set_result("done")

        self.assertFalse(f.running())
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:10,代码来源:future_test.py

示例4: test_done

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_done(self):
        f = Future()

        self.assertFalse(f.done())

        f.set_result("done")

        self.assertTrue(f.done())
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:10,代码来源:future_test.py

示例5: test_continue_with_on_success

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_continue_with_on_success(self):
        f = Future()
        f.set_result(1)

        def continuation(future):
            return future.result() + 1

        result = f.continue_with(continuation).result()
        self.assertEqual(2, result)
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:11,代码来源:future_test.py

示例6: test_combine_futures_exception

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_combine_futures_exception(self):
        f1, f2, f3 = Future(), Future(), Future()

        combined = combine_futures(f1, f2, f3)

        e = RuntimeError("error")
        f1.set_result("done")
        f2.set_result("done")
        f3.set_exception(e)

        self.assertEqual(e, combined.exception())
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:13,代码来源:future_test.py

示例7: test_continue_with_throws_exception

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_continue_with_throws_exception(self):
        f = Future()
        e = RuntimeError("error")

        def continue_func(f):
            raise e

        n = f.continue_with(continue_func)
        f.set_result("done")

        self.assertFalse(n.is_success())
        self.assertEqual(n.exception(), e)
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:14,代码来源:future_test.py

示例8: test_add_callback_after_completion_with_success

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_add_callback_after_completion_with_success(self):
        f = Future()
        f.set_result("done")

        counter = [0]

        def callback(future):
            counter[0] += 1
            self.assertEqual(future.result(), "done")

        f.add_done_callback(callback)
        self.assertEqual(counter[0], 1)
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:14,代码来源:future_test.py

示例9: test_combine_futures

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
    def test_combine_futures(self):
        f1, f2, f3 = Future(), Future(), Future()

        combined = combine_futures(f1, f2, f3)

        f1.set_result("done1")
        self.assertFalse(combined.done())

        f2.set_result("done2")
        self.assertFalse(combined.done())

        f3.set_result("done3")
        self.assertEqual(combined.result(), ["done1", "done2", "done3"])
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:15,代码来源:future_test.py

示例10: multiply

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
 def multiply(self, x, y):
     f = Future()
     f.set_result(x * y)
     return f
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:6,代码来源:future_test.py

示例11: add_one

# 需要导入模块: from hazelcast.future import Future [as 别名]
# 或者: from hazelcast.future.Future import set_result [as 别名]
 def add_one(self, x):
     f = Future()
     f.set_result(x + 1)
     return f
开发者ID:hazelcast,项目名称:hazelcast-python-client,代码行数:6,代码来源:future_test.py


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