本文整理汇总了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))
示例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
示例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())
示例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())
示例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)
示例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())
示例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)
示例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)
示例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"])
示例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
示例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