MCPcopy Create free account
hub / github.com/EasyIME/PIME / maybe_future

Function maybe_future

python/python3/tornado/gen.py:555–573  ·  view source on GitHub ↗

Converts ``x`` into a `.Future`. If ``x`` is already a `.Future`, it is simply returned; otherwise it is wrapped in a new `.Future`. This is suitable for use as ``result = yield gen.maybe_future(f())`` when you don't know whether ``f()`` returns a `.Future` or not. .. deprecat

(x: Any)

Source from the content-addressed store, hash-verified

553
554
555def maybe_future(x: Any) -> Future:
556 """Converts ``x`` into a `.Future`.
557
558 If ``x`` is already a `.Future`, it is simply returned; otherwise
559 it is wrapped in a new `.Future`. This is suitable for use as
560 ``result = yield gen.maybe_future(f())`` when you don't know whether
561 ``f()`` returns a `.Future` or not.
562
563 .. deprecated:: 4.3
564 This function only handles ``Futures``, not other yieldable objects.
565 Instead of `maybe_future`, check for the non-future result types
566 you expect (often just ``None``), and ``yield`` anything unknown.
567 """
568 if is_future(x):
569 return x
570 else:
571 fut = _create_future()
572 fut.set_result(x)
573 return fut
574
575
576def with_timeout(

Callers

nothing calls this directly

Calls 2

is_futureFunction · 0.90
_create_futureFunction · 0.85

Tested by

no test coverage detected