# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from qcore import MarkerObject from asynq import asynq, async_proxy, result, ConstFuture from collections import deque # TODO(alex): finish w/this test empty = MarkerObject(u'empty @ asynq.channels') future_empty = ConstFuture(empty) future_false = ConstFuture(False) future_true = ConstFuture(True) class Channel(object): def __init__(self, capacity=256): self.capacity = capacity self.items = deque() self.futures = deque() @async_proxy(pure=True) def push(self, value, should_await=True): if self.futures: future = self.futures.popleft() future.set_value(value)
def pull(self, should_await=True): if self.items: return ConstFuture(self.items.popleft()) return _pull_async(self) \ if should_await else future_empty
def proxied_fn(): return ConstFuture("capybaras!")
def async_proxied_fn(): return ConstFuture("async_proxied_fn")
def get(self, key): self._dependency(key) value = self._local.get(key) if value is miss: # No item is cached locally return self._create_batch_item("get", key) return ConstFuture(miss if value is none else value)
def async_proxied_fn(): return ConstFuture('async_proxied_fn')
def test_result(): with AssertRaises(AssertionError): result(ConstFuture(None)) with AssertRaises(AsyncTaskResult): result(None)