How to use the streams.CountQueuingStrategy function in streams

To help you get started, we’ve selected a few streams examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozilla-b2g / gaia-email-libs-and-more / js / search / filtering_stream.js View on Github external
},
    transform(change, enqueue, done) {
      if (isDeletion(change)) {
        enqueue({ change, gather: null });
      } else {
        // (avoid gathering data for already-removed items)
        if (queuedSet.has(change.id)) {
          logic(ctx, 'gathering', { id: change.id });
          let gatherInto = inputToGatherInto(change);
          enqueue({ change, gather: rootGatherer.gather(gatherInto) });
        }
      }
      done();
    },
    writableStrategy: new CountQueuingStrategy({ highWaterMark: 1 }),
    readableStrategy: new CountQueuingStrategy({ highWaterMark: 1 })
  });

  let filterStream = new TransformStream({
    flush(enqueue, close) {
      close();
    },
    transform({ change, gather }, enqueue, done) {
      if (!gather) {
        // This is a deletion.  And we care about it or we wouldn't be here.
        enqueue(change);
        done();
      } else {
        logic(ctx, 'gatherWait', { id: change.id });
        gather.then((gathered) => {
          logic(ctx, 'gathered', { id: change.id });
          // It's possible the item got removed after we kicked off the gather.
github mozilla-b2g / gaia-email-libs-and-more / js / search / filtering_stream.js View on Github external
//bufferingStream.readable.pipeTo(gatherStream.writable);
  gatherStream.readable.pipeThrough(filterStream).pipeTo(new WritableStream({
    start() {
    },
    write(change) {
      onFilteredUpdate(change);
    },
    close() {
      // I don't think anything actually cares?  Unless we should be propagating
      // through to the moot callback?
    },
    abort(ex) {
      logic(ctx, 'filteringStreamAbortError', { ex, stack: ex.stack });
    }
  }, new CountQueuingStrategy({ highWaterMark: 1 })));

  return {
    /**
     * This is how we are fed data/changes from the database.
     */
    consider: (change) => {
      if (!isDeletion(change)) {
        // - add/change, process for filtering
        queuedSet.add(change.id);
        gatherStream.writable.write(change);
      } else {
        // - removal
        // We don't need to check if the value's in here, performing the
        // deletion is sufficient for us to ensure that if it's in the pipeline
        // that it does not get reported.
        queuedSet.delete(change.id);
github mozilla-b2g / gaia-email-libs-and-more / js / search / filtering_stream.js View on Github external
change.matchInfo = matchInfo;
            enqueue(change);
          } else {
            // - No Match!
            // We may need to issue a retraction... delete and check RV.
            if (knownFilteredSet.delete(change.id)) {
              change = shallowClone(change);
              mutateChangeToResembleDeletion(change);
              enqueue(change);
            }
          }
          done();
        });
      }
    },
    writableStrategy: new CountQueuingStrategy({ highWaterMark: 1 }),
    readableStrategy: new CountQueuingStrategy({ highWaterMark: 1 })
  });

  //bufferingStream.readable.pipeTo(gatherStream.writable);
  gatherStream.readable.pipeThrough(filterStream).pipeTo(new WritableStream({
    start() {
    },
    write(change) {
      onFilteredUpdate(change);
    },
    close() {
      // I don't think anything actually cares?  Unless we should be propagating
      // through to the moot callback?
    },
    abort(ex) {
      logic(ctx, 'filteringStreamAbortError', { ex, stack: ex.stack });

streams

A lazy streams library for functional composition in JavaScript.

MIT
Latest version published 22 days ago

Package Health Score

70 / 100
Full package analysis