@@ -49,7 +49,9 @@ def then(self, callback):
49
49
>>> # The inserted callback will print the return value when
50
50
>>> # receiving the response from "worker1"
51
51
>>> cb_fut = fut.then(callback)
52
- >>> chain_cb_fut = cb_fut.then(lambda x : print(f"Chained cb done. {x.wait()}"))
52
+ >>> chain_cb_fut = cb_fut.then(
53
+ >>> lambda x : print(f"Chained cb done. {x.wait()}")
54
+ >>> )
53
55
>>> fut.set_result(5)
54
56
>>>
55
57
>>> # Outputs are:
@@ -91,14 +93,34 @@ def set_result(self, result):
91
93
92
94
def collect_all (futures ):
93
95
r"""
94
- Collects the Futures into a single combined Future that is completed
95
- when all of the sub-futures are completed.
96
+ Collects the provided :class:`~torch.futures.Future` objects into a single
97
+ combined :class:`~torch.futures.Future` that is completed when all of the
98
+ sub-futures are completed.
96
99
97
100
Arguments:
98
- futures: a list of Futures
101
+ futures (list) : a list of :class:`~torch.futures.Future` objects.
99
102
100
103
Returns:
101
- Returns a Future object to a list of the passed in Futures.
104
+ Returns a :class:`~torch.futures.Future` object to a list of the passed
105
+ in Futures.
106
+
107
+ Example::
108
+ >>> import torch
109
+ >>>
110
+ >>> fut0 = torch.futures.Future()
111
+ >>> fut1 = torch.futures.Future()
112
+ >>>
113
+ >>> fut = torch.futures.collect_all([fut0, fut1])
114
+ >>>
115
+ >>> fut0.set_result(0)
116
+ >>> fut1.set_result(1)
117
+ >>>
118
+ >>> fut_list = fut.wait()
119
+ >>> print(f"fut0 result = {fut_list[0].wait()}")
120
+ >>> print(f"fut1 result = {fut_list[1].wait()}")
121
+ >>> # outputs:
122
+ >>> # fut0 result = 0
123
+ >>> # fut1 result = 1
102
124
"""
103
125
return torch ._C ._collect_all (futures )
104
126
@@ -108,9 +130,11 @@ def wait_all(futures):
108
130
the list of completed values.
109
131
110
132
Arguments:
111
- futures: a list of Futures
133
+ futures (list) : a list of :class:`~torch.futures.Future` object.
112
134
113
135
Returns:
114
- A list of the completed Future results
136
+ A list of the completed :class:`~torch.futures.Future` results. This
137
+ method will throw an error if ``wait`` on any
138
+ :class:`~torch.futures.Future` throws.
115
139
"""
116
140
return [fut .wait () for fut in torch ._C ._collect_all (futures ).wait ()]
0 commit comments