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

screams

v0.0.0

Published

Simpler object streams using generators

Downloads

3

Readme

Screams Build Status

Simpler object streams using generators. Intended to mimic node's streams but without complexity. There are no more event emitters and fewer states to handle. Designed to be used with co.

You might be interested in archan.

Example

Readable Stream

var Scream = require('screams')

var stream = new Scream({
  highWaterMark: 2
})

// push routine
co(function* () {
  yield* this.reading()

  var i = 1

  while (i <= 10)
    yield stream.push(i++)

  stream.push(null)
})()

// pull routine
co(function* () {
  var res = []
  var obj

  while (obj = yield* stream.read())
    res.push(obj)

  res.should.eql([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})(done)

API

var stream = new Scream([options])

Options:

  • highWaterMark: 16 - maximum number of items to store in the buffer.

stream.onerror = function (err) {}

This is called if any errors occur that are otherwise not handled. By default, it just throws the error. This is basically the same as .on('error', listener).

Readable Properties

For consumers

yield* stream.read()

Returns the next object in the stream. This is it - there are no readable or data events. If there's no data to read from the buffer, it'll wait until there is.

For implementors

yield* stream.reading()

If the stream is currently being consumed, this will yield immediately. Otherwise, it will yield the first time .read() is called.

This eliminates the need for an implementable ._read() method - just push data in a separate coroutine.

You can ignore this if you want to just push data to the stream immediately. In node, you have to do .read(0) to signify that.

[yield] stream.push(val)

Push a value to a stream.

Note that in the example, we signify the end of the stream by pushing a null value. However, if we pushed 0, then the while loop would consider that the end of the stream. Handling the values and consumption is up to the implementor.

If you push an error, that error will be thrown when the consumer .read()s that value. That doesn't necessarily mean the stream is ended though - you can have a stream of Errors whose values must be caught each time.

yield is optional and is meant to handle backpressure. If the buffer length is below the high water mark, it will yield immediately, otherwise it will wait until a "drain" event.

stream.pipe(stream, [options])

NOT YET IMPLEMENTED

stream can be Scream or a node Stream.Writable instance. Backpressure is handled correctly.

Options:

  • end - call stream.end() when the source stream is done.
stream.unpipe(stream, [options])

NOT YET IMPLEMENTED

stream can be Scream or a node Stream.Writable instance.

Writable Properties

NOT YET IMPLEMENTED

For consumers

[yield] stream.write(val)

NOT YET IMPLEMENTED

Write a value to the stream. yield is optional and is meant to handle back pressure. If the buffer length is below the high water mark, it will yield immediately, otherwise it will wait until the next "drain" event.

Note: backpressure is not compatible with node streams.

[yield] stream.end([val])

NOT YET IMPLEMENTED

Signify the end of the stream. yield is optional. If you yield, it will suspend execution until the stream is flushed (i.e. the finish event).

For implementors

stream._write = function* (val) {}

NOT YET IMPLEMENTED

An implementable generator function. This method must be implemented if the stream is to be used as a writable stream. For example, a pass through stream would just be:

stream._write = function* (val) {
  yield this.push(val)
}
stream._flush = function* () {}

NOT YET IMPLEMENTED

An optional implementable generator function. This method is called after all the writes have been flushed.

License

The MIT License (MIT)

Copyright (c) 2013 Jonathan Ong [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.