Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/szmarczak/defer-to-connect

The safe way to handle the `connect` socket event
https://github.com/szmarczak/defer-to-connect

connect nodejs socket

Last synced: about 2 months ago
JSON representation

The safe way to handle the `connect` socket event

Awesome Lists containing this project

README

        

# defer-to-connect

> The safe way to handle the `connect` socket event

[![Coverage Status](https://coveralls.io/repos/github/szmarczak/defer-to-connect/badge.svg?branch=master)](https://coveralls.io/github/szmarczak/defer-to-connect?branch=master)

Once you receive the socket, it may be already connected (or disconnected).

To avoid checking that, use `defer-to-connect`. It'll do that for you.

## Usage

```js
const deferToConnect = require('defer-to-connect');

deferToConnect(socket, () => {
console.log('Connected!');
});
```

## API

### deferToConnect(socket, connectListener)

Calls `connectListener()` when connected.

### deferToConnect(socket, listeners)

#### listeners

An object representing `connect`, `secureConnect` and `close` properties.

Calls `connect()` when the socket is connected.

Calls `secureConnect()` when the socket is securely connected.

Calls `close()` when the socket is destroyed.

## License

MIT