Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 _no_value = object() | |
| 6 | |
| 7 class LazyValue(object): | |
|
not at google - send to devlin
2012/07/18 10:39:15
I realised today that this isn't *like* Java's Fut
cduvall
2012/07/18 21:26:10
Done.
| |
| 8 def __init__(self, value=_no_value, error=None, delegate=None): | |
| 9 self._value = value | |
| 10 self._error = error | |
| 11 self._delegate = delegate | |
| 12 if (self._value is _no_value and | |
| 13 self._error is None and | |
| 14 self._delegate is None): | |
|
not at google - send to devlin
2012/07/18 10:39:15
what's wrong with ==
cduvall
2012/07/18 21:26:10
See previous comment.
| |
| 15 raise ValueError('Must have either a value, error, or delegate.') | |
| 16 | |
| 17 def Get(self): | |
|
not at google - send to devlin
2012/07/18 10:39:15
documentation
cduvall
2012/07/18 21:26:10
Done.
| |
| 18 if self._value is not _no_value: | |
| 19 return self._value | |
| 20 if self._error is not None: | |
|
not at google - send to devlin
2012/07/18 10:39:15
what's wrong with !=
cduvall
2012/07/18 21:26:10
See previous comment.
| |
| 21 raise self._error | |
| 22 try: | |
| 23 self._value = self._delegate.Get() | |
| 24 except Exception as self._error: | |
| 25 raise | |
| 26 return self._value | |
| OLD | NEW |