npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crp-stream-client

v0.0.12

Published

CrowdProcess API Client for streaming tasks, results and errors

Downloads

30

Readme

task-stream-client

Getting it

Install it

npm install --save crp-stream-client

Require and Instantiate

var Client = require('crp-stream-client');

var client = Client({
  token: 'e1ffe165-10ad-beef-b00b-115B0Ab0053d'
});

You can also instantiate it with an email and password. You can generate a token like the one above with crp-account-client.

Use it

This module exposes:

  • a writable Tasks stream;
  • a readable Results stream;
  • a readable Errors stream;
  • a duplex stream with all of the above.

And they work like you would expect: you write tasks to the Task stream, read results from the Result stream and errors from the Error stream.

The duplex stream is a convenience stream that you can write tasks to it, it emits data events when results arrive, and error events when errors arrive.

They are all Object streams, meaning you should write objects and expect objects as well.

Tasks Stream

Tasks stream accepts any javascript object that is JSON stringifyable. You write it to tasksStream parsed, and it will arrive also parsed at the Run function, just like you would expect.

Suppose the jobId value used in the examples corresponds to a valid job (created with crp-job-client) that returns whatever it gets (an echo job really, like function Run (d) { return d; }).

var tasks = client(jobId).Tasks();

var n = 1000;
while (n--) {
  tasks.write({
    name: 'something',
    n: n
  });
}

Results Stream

The Results stream takes an options object, which can have a timeout and a stream.

timeout must be a string that has a number and a time unit, such as 100ms or 1s or 1m. The timeout means the result stream will end after timeout time has passed since the last result was received.

stream is a boolean that indicates whether you'd like to receive results as soon as they arrive from the browsers, or you want to fetch them from the database when it's done.

If the job above is an echo job, we'll get 1000 results:

var results = client(jobId).Results({
  timeout: '5s',
  stream: true
});
results.on('data', onData);
function onData (data) {
  console.log('result:', data);
}

Errors Stream

Sometimes, there are errors in running your tasks, and you can get them like this:

var errors = client(jobId).Errors({
  timeout: '5s',
  stream: true
});
errors.on('data', onError);
function onError (data) {
  console.error(data);
}

The Errors stream takes the same options object as described in the Results stream.