示例#1
0
  private boolean step() {
    if (next != NONE) return true;

    while (next == NONE) {
      if (buffer.isEmpty()) {
        if (completed) {
          return false;
        } else if (sourceIter.hasNext()) {
          Object iter = null;
          if (multi) iter = xf.applyTo(RT.cons(null, sourceIter.next()));
          else iter = xf.invoke(null, sourceIter.next());

          if (RT.isReduced(iter)) {
            xf.invoke(null);
            completed = true;
          }
        } else {
          xf.invoke(null);
          completed = true;
        }
      } else {
        next = buffer.remove();
      }
    }
    return true;
  }
示例#2
0
 Object doCommute(Ref ref, IFn fn, ISeq args) {
   if (!info.running()) throw retryex;
   if (!vals.containsKey(ref)) {
     Object val = null;
     try {
       ref.lock.readLock().lock();
       val = ref.tvals == null ? null : ref.tvals.val;
     } finally {
       ref.lock.readLock().unlock();
     }
     vals.put(ref, val);
   }
   ArrayList<CFn> fns = commutes.get(ref);
   if (fns == null) commutes.put(ref, fns = new ArrayList<CFn>());
   fns.add(new CFn(fn, args));
   Object ret = fn.applyTo(RT.cons(vals.get(ref), args));
   vals.put(ref, ret);
   return ret;
 }