Suppress tabs permission warning if there is already a browsingHistory warning.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / future.py
blob2f600991e675da5558bdf14fb489a31bfa41bb87
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.
5 import sys
7 _no_value = object()
10 def Collect(futures):
11 '''Creates a Future which returns a list of results from each Future in
12 |futures|.
13 '''
14 return Future(callback=lambda: [f.Get() for f in futures])
17 class Future(object):
18 '''Stores a value, error, or callback to be used later.
19 '''
20 def __init__(self, value=_no_value, callback=None, exc_info=None):
21 self._value = value
22 self._callback = callback
23 self._exc_info = exc_info
24 if (self._value is _no_value and
25 self._callback is None and
26 self._exc_info is None):
27 raise ValueError('Must have either a value, error, or callback.')
29 def Get(self):
30 '''Gets the stored value, error, or callback contents.
31 '''
32 if self._value is not _no_value:
33 return self._value
34 if self._exc_info is not None:
35 self._Raise()
36 try:
37 self._value = self._callback()
38 return self._value
39 except:
40 self._exc_info = sys.exc_info()
41 self._Raise()
43 def _Raise(self):
44 exc_info = self._exc_info
45 raise exc_info[0], exc_info[1], exc_info[2]