# awync-events

> Awync EventEmitter

Latest version **1.1.5** (published 2016-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install awync-events
pnpm add awync-events
yarn add awync-events
bun add awync-events
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.5 |
| Published | 2016-11-17 |
| First published | 2016-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tolgahan Albayrak |
| Maintainers | tolgahan |
| Keywords | awync, events, eventemitter |

## Links

- npm: https://www.npmjs.com/package/awync-events
- Repository: https://github.com/tlghn/awync-events
- Homepage: https://github.com/tlghn/awync-events#readme
- Issues: https://github.com/tlghn/awync-events/issues
- npm.io page: https://npm.io/package/awync-events

## Dependencies (1)

- [awync](https://npm.io/package/awync.md) ^1.2.5

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.1.5 (latest) — 2016-11-17
- 1.1.4 — 2016-11-12
- 1.1.3 — 2016-11-09
- 1.1.2 — 2016-11-06
- 1.1.1 — 2016-11-05
- 1.1.0 — 2016-11-05
- 1.0.2 — 2016-11-04
- 1.0.1 — 2016-11-04
- 1.0.0 — 2016-11-04

## README

# awync-events
Awync way EventEmitter

## Installing
```
npm i awync-evets --save
```

## Usage

### Basic Usage

```
const EventEmitter = require('awync-events');
const awync = require('awync');
const ee = new EventEmitter();

awync(function*(){
    var result = yield ee.when.test();
    console.log(result);
    // output: Easy events
});

setTimeout(function(){
    ee.emit('test', 'Easy events');
}, 1000);

```


### Attaching to Others

```
const EE = require('awync-events');
const awync = require('awync');
const net = require('net');
const server = new net.Server();
EE(server);

awync(function*(){
    server.listen(3000);
    
    yield server.when.listening();
    console.log('Listening');
});

```


## API

- EventEmitter.***when***
    > Waits until requested event is emitted. 
    Returns the passed parameters on emit 
    
    **If single argument is passed on emit;**
    
    If that argument is not an Error then it will be yielded without boxing. 
    
     Otherwise, it will be thrown

	**If multiple arguments are passed on emit then**
	
	If first argument is error then it will be thrown and all passed arguments will be stored on firstArgument.args property.
	
	If arguments length is 2 and first argument is null or undefined then second argument will be yielded without boxing.
	
	Otherwise, all arguments will be yielded as array
        
        
    ```
    var eventResults = yield emitter.wait.someEvent();
    ```

- EventEmitter.***whichever(name1, name2,...nameN)***
    > Waits until one of requested event is emitted. 
    Returns an object with two parameters *{**name**, **args**}*
    
    ```
        awync(function*(){
            try{
                socket.connect();
                
                var eventResults = yield socket.whichever('error', 'connect');
                
                // eventResults.name == 'connect'
                // eventResults.args == passed arguments by calling emit('connect')
    
                // Since the error on first parameter will be thrown,
                // This lines will be unreachable if 'error' event is emitted.
                // So, if below code is executed then we will be sure that 'connect' event is emitted.
                console.log('Connected!');
            } catch(err){
                // err.name == 'error'
                // err.args == passed arguments by calling emit('error')
            }
        });
    ```


- EventEmitter.***whatever()***
    > Waits until any event is emitted.
    Returns an object with two parameters *{**name**, **args**}*
    
    ```
        awync(function*(){
            
            while(true){
                var result = yield emitter.whatever();
                console.log("Event %s is emitted with args: %s", result.name, result.args);
            }

        });
        
        setInterval(function(){
            emitter.emit('some random event name ' + Math.random(), Date.now());
        }, 1000);
    ```

## Change Log
- 1.1.0 whatever(), whichever() API functions are added
- 1.0.0 Initial Release

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