# timeout-callback

> callback function wrapper with timeout functionality

Latest version **2.0.2** (published 2018-10-31) · 0 weekly downloads

## Install

```sh
npm install timeout-callback
pnpm add timeout-callback
yarn add timeout-callback
bun add timeout-callback
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score; declining downloads.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2018-10-31 |
| First published | 2015-02-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Maintainers | jakub.knejzlik |

## Links

- npm: https://www.npmjs.com/package/timeout-callback
- Repository: https://github.com/jakubknejzlik/node-timeout-callback
- Homepage: https://github.com/jakubknejzlik/node-timeout-callback#readme
- Issues: https://github.com/jakubknejzlik/node-timeout-callback/issues
- npm.io page: https://npm.io/package/timeout-callback

## Dependencies (1)

- [mocha](https://npm.io/package/mocha.md) ^5.2.0

## Recent versions

- 2.0.2 (latest) — 2018-10-31
- 2.0.1 — 2018-03-29
- 2.0.0 — 2017-05-15
- 1.0.0 — 2016-04-16
- 0.0.4 — 2015-06-11
- 0.0.3 — 2015-02-17
- 0.0.2 — 2015-02-17
- 0.0.1 — 2015-02-17

## README

When working with socket.io emitted message with callback, if the socket disconnect before answering (or doesn't answer at all) the callback function hangs up forever. In these situations you need to timeout this callback.

This wrapper makes this task easy. Just do:

	var timeoutCallback = require('timeout-callback');
	
	socket.emit('message-expecting-answer',timeoutCallback(function(err,arg1,arg2){
		console.log('this log is always displayed!');
	}));
	
	
	
By default timeout is set to 10 seconds, you can change this interval by specifying timeout as first argument (in milliseconds)

	timeoutCallback(60*1000,myCallbackFunction);

If the timeout is reached, the callback is called with error ```new Error('callback timeout')``` as the first argument.

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