🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

streams-set

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

streams-set

Maintain a set of open streams

latest
Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

streams-set

Maintain a set of open streams

npm install streams-set

build status

Usage

var streamsSet = require('./')
var net = require('net')

var activeSockets = streamsSet()

var server = net.createServer(function (socket) {
  // when the socket ends/errors it will automatically be removed from the set
  activeSockets.add(socket)

  // will print "set size is 1"
  console.log('set size is', activeSockets.size)
  socket.on('close', function () {
    // will print "set size is 0"
    console.log('set size is', activeSockets.size)
  })
})

server.listen(10000, function () {
  var socket = net.connect(10000)
  // connect and destroy
  socket.on('connect', function () {
    socket.destroy()
  })
})

API

var set = streamsSet()

Create a new set

set.add(stream)

Add a stream to the set. If the stream ends/errors it will be removed from the set

set.remove(stream)

Manually remove a stream from the set

set.has(stream)

Check if a stream is in the set

set.streams

An array of streams in the set

set.size

The current size of the set

set.forEach(fn)

Iterate over all streams in the set

stream = set.get(index)

Get a stream from the set

License

MIT

FAQs

Package last updated on 08 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts