1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
10 def Collect(futures
, except_pass
=None):
11 '''Creates a Future which returns a list of results from each Future in
12 |futures|. |except_pass| should be one or more exceptions to ignore when
13 calling Get on the futures.
19 resolved
.append(f
.Get())
20 # "except None" will simply not catch any errors
24 return Future(callback
=resolve
)
28 '''Stores a value, error, or callback to be used later.
30 def __init__(self
, value
=_no_value
, callback
=None, exc_info
=None):
32 self
._callback
= callback
33 self
._exc
_info
= exc_info
34 if (self
._value
is _no_value
and
35 self
._callback
is None and
36 self
._exc
_info
is None):
37 raise ValueError('Must have either a value, error, or callback.')
40 '''Gets the stored value, error, or callback contents.
42 if self
._value
is not _no_value
:
44 if self
._exc
_info
is not None:
47 self
._value
= self
._callback
()
50 self
._exc
_info
= sys
.exc_info()
54 exc_info
= self
._exc
_info
55 raise exc_info
[0], exc_info
[1], exc_info
[2]