# defer-to-connect

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

Latest version **2.0.1** (published 2021-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install defer-to-connect
pnpm add defer-to-connect
yarn add defer-to-connect
bun add defer-to-connect
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2021-02-24 |
| First published | 2018-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 0 |
| Unpacked size | 5.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Szymon Marczak |
| Maintainers | szmarczak |
| Keywords | socket, connect, event |

## Links

- npm: https://www.npmjs.com/package/defer-to-connect
- Repository: https://github.com/szmarczak/defer-to-connect
- Homepage: https://github.com/szmarczak/defer-to-connect#readme
- Issues: https://github.com/szmarczak/defer-to-connect/issues
- npm.io page: https://npm.io/package/defer-to-connect

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2021-02-24
- 2.0.0 — 2020-01-28
- 1.1.3 — 2020-01-28
- 1.1.2 — 2020-01-28
- 1.1.1 — 2019-12-04
- 1.1.0 — 2019-11-02
- 1.0.2 — 2019-01-18
- 1.0.1 — 2018-08-25
- 1.0.0 — 2018-08-13

## 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).<br>
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.<br>
Calls `secureConnect()` when the socket is securely connected.<br>
Calls `close()` when the socket is destroyed.

## License

MIT

---
_Source: https://npm.io/package/defer-to-connect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
