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

cocker

v1.0.4

Published

Cocker, a socket module to aggressively handle connection retries..

Downloads

236

Readme

Cocker

NPM VERSION CODACY BADGE CODECLIMATE-TEST-COVERAGE LICENSE

NODE VERSION TRAVIS CI BUILD BUILD STATUS DEVDEPENDENCY STATUS

NPM MONTHLY NPM YEARLY NPM TOTAL

NPM GRAPH

Cocker, a socket module to aggressively handle connection retries.

NOTE: It directly inherits from net.Socket.

Table of Contents


Install

$ npm install cocker [-g]

require:

const Cocker  = require( 'cocker' );

Run Tests

$ cd cocker/
$ npm test

to execute a single test file simply do:

 $ node test/file-name.js

Constructor

Arguments between [ ] are optional.

Cocker( [ Object options ] )

or

new Cocker( [ Object options ] )

Options

NOTE: default options are listed.

It accepts a configuration hash/object:

option
{
 , address : Object
 , connection : Object
 , reconnection : Object
}
option.address (default)
{
    host : '127.0.0.1'
    , port : 0
    , family : null
    /*
     * Specify an IPC endpoint, like a unix domain socket, if a string is
     * provided, the TCP-specific options above are ignored.
     * For further details, see "Identifying paths for IPC connections" in 
     * the /api/net section.
     */
    , path : null
 }
option.address (additional options for net.Socket)
{   
    // should connect from
    localAddress : undefined
    , localPort: undefined
    // custom lookup and hints
    , lookup : dns.lookup 
    , hints : 0
 }
option.connection
 {
    encoding : null
    , keepAlive : true
    , timeout : 0
    , noDelay : true
    , allowHalfOpen : false
 }
option.reconnection
 {
    trials : 3
    , interval : 1000
    /*
     * A value to use for calculating the pause between two
     * connection attempts. Default value is the golden ratio.
     * Final value is calculated as:
     * interval * Math.pow( factor, curr.attempts + 1 )
     */
    , factor : ( Math.sqrt( 5 ) + 1 ) / 2
 }

Properties

NOTE: do not mess up with these properties.

a property that holds the current configuration object
Cocker.options : Object
current number of connection attempts
Cocker.attempts : Number
a flag to signal the current status of the connection
Cocker.lost : Boolean
a flag used to disable reconnection (after #hunt Promise resolution)
Cocker.stop : Boolean
current lapse of time (to wait) until the next connection attempt
Cocker.lapse : Number

Methods

all the methods from net.Socket module are inherited.

| name | description | |:-------------------------|:-------------------------------------------------| | bye | end the connection. | | run | connect to a socket or attempting to. | | die | end the connection. (Promise) | | hunt | connect to a socket or attempting to. (Promise)| | prey | connect using a list of hosts. (Promise) | | watch| re-connect after losing the current connection. (Promise) |

Arguments between [ ] are optional.

Cocker.bye

end the connection (without re-connecting).
'bye' : function ( [ Buffer | String data [, String enc ] ] ) : undefined

Cocker.run

connect to a socket or attempting to (k times).
// it optionally accepts a cocker option object to reconfigure the socket.
'run' : function ( [ Object cocker_options ] ) : undefined

Cocker.die

end the connection (without re-connecting).
// Promise will not be resolved until 'lost' event
'die' : function ( [ Buffer | String data [, String enc ] ] ) : Promise

Cocker.hunt

connect to a socket or attempting to (k times).
/*
 * Try to connect to a socket. Promise will not be resolved until 'online',
 * rejected after 'lost' event; it optionally accepts a cocker option object
 * to reconfigure the socket.
 */
'hunt' : function ( [ Object cocker_options ] ) : Promise

Cocker.prey

try to connect until success, using a list of optional hosts/config.
/*
 * It recursively scan a list, using #hunt Promises. The #prey Promise will 
 * not be resolved until a connection will be made, definitively rejected
 * when no hosts had accepted one. 
 * Every host in the list should be an object like Cocker.options.address.
 */
'prey' : function ( Array hosts ) : Promise

Cocker.watch

try to re-connect after losing the current connection.
/*
 * When the current established connection is lost, it tries to reconnect.
 * This Promise has the same resolution as for #hunt, the only difference is
 * that this Promise was "registered" on socket disconnection, then it will be
 * resolved/rejected only after capturing a 'lost' event from the current
 * broken connection. See examples.
 */
'watch' : function ( [ Object cocker_options ] ) : Promise

Events

all the events from net.Socket module are inherited.

!online: connection was established.
// when: soon after socket !connect event
'online' : function ( Object address  )
!offline: connection is down.
// when: on the first !close event for the current socket
'offline' : function ( Object address  )
!attempt: current connection attempt.
// when: after !offline, on every connection attempt, until !lost or !online 
'attempt' : function ( Number t, Object address, Number lapse )
!lost: no other attempts will be made, connection is definitively lost.
// when: soon before the last !close event.
'lost' : function ( Number t, Object address, Number lapse )

Examples

Simple Mode

Native Promises

See examples.

MIT License

Copyright (c) 2013-present < Guglielmo Ferri : [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.