UNPKG

951 BMarkdownView Raw
1# defer-to-connect
2
3> The safe way to handle the `connect` socket event
4
5[![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)
6
7Once you receive the socket, it may be already connected (or disconnected).<br>
8To avoid checking that, use `defer-to-connect`. It'll do that for you.
9
10## Usage
11
12```js
13const deferToConnect = require('defer-to-connect');
14
15deferToConnect(socket, () => {
16 console.log('Connected!');
17});
18```
19
20## API
21
22### deferToConnect(socket, connectListener)
23
24Calls `connectListener()` when connected.
25
26### deferToConnect(socket, listeners)
27
28#### listeners
29
30An object representing `connect`, `secureConnect` and `close` properties.
31
32Calls `connect()` when the socket is connected.<br>
33Calls `secureConnect()` when the socket is securely connected.<br>
34Calls `close()` when the socket is destroyed.
35
36## License
37
38MIT