# alinex-once

> short helper function which lets a function run only once also if called multiple times

Latest version **0.1.1** (published 2015-02-11) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install alinex-once
pnpm add alinex-once
yarn add alinex-once
bun add alinex-once
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2015-02-11 |
| First published | 2015-02-11 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Alexander Schilling |
| Maintainers | alinex |

## Links

- npm: https://www.npmjs.com/package/alinex-once
- Repository: https://github.com/alinex/node-once
- Homepage: http://alinex.github.io/node-once/
- Issues: https://github.com/alinex/node-once/issues
- npm.io page: https://npm.io/package/alinex-once

## Recent versions

- 0.1.1 (latest) — 2015-02-11
- 0.0.1 — 2015-02-11

## README

Package: alinex-once
=================================================

[![Build Status] (https://travis-ci.org/alinex/node-once.svg?branch=master)](https://travis-ci.org/alinex/node-once)
[![Coverage Status] (https://coveralls.io/repos/alinex/node-once/badge.png?branch=master)](https://coveralls.io/r/alinex/node-once?branch=master)
[![Dependency Status] (https://gemnasium.com/alinex/node-once.png)](https://gemnasium.com/alinex/node-once)

Short helper function which lets a function run only once also if called multiple
times.

This is useful in event driven calls in which the callback may be called multiple
times or then a function is called in parallel an have to initialize once before
going on.

It is one of the modules of the [Alinex Universe](http://alinex.github.io/node-alinex)
following the code standards defined there.


Install
-------------------------------------------------

The easiest way is to let npm add the module directly:

    > npm install alinex-fs --save

[![NPM](https://nodei.co/npm/alinex-once.png?downloads=true&stars=true)](https://nodei.co/npm/alinex-once/)


Usage
-------------------------------------------------
First the library have to be included:

    var once = require('alinex-once');

Now a function may be wrapped with the once method:

    var fn = once.skip(function(a, b, cb) {
      return cb(null, a + b);
    });

And now you can call the function as normal but on the second call it will
return imediately without running the code:

    fn(2, 3, function(err, x) {
      // x will now be 5
      fn(2, 3, function(err, x) {
        // err will now be set
      });
    });

You may use this helper in case of initialization (wait) there a specific
method have to run once before any other call can succeed. Or then events
are involved and an error event will trigger the callback and the end event will
do the same.


API
-------------------------------------------------

- throw - throw an error if it is called a second time
- skip - skip execution and immediately return on second call
- atime - only run it once at a time but response all calls with the result
- wait - the second call will get return with the same result


License
-------------------------------------------------

Copyright 2015 Alexander Schilling

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

>  <http://www.apache.org/licenses/LICENSE-2.0>

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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