# ascs

> provide the async/await like C# 4.5

Latest version **0.2.5** (published 2015-07-23) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install ascs
pnpm add ascs
yarn add ascs
bun add ascs
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.5 |
| Published | 2015-07-23 |
| First published | 2014-05-18 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | drzunny |
| Maintainers | drzlab |
| Keywords | async, await, javascript, C# |

## Links

- npm: https://www.npmjs.com/package/ascs
- Repository: https://github.com/drzunny/ascs
- Homepage: https://github.com/drzunny/ascs#readme
- Issues: https://github.com/drzunny/ascs/issues
- npm.io page: https://npm.io/package/ascs

## Dependencies (1)

- [fibers](https://npm.io/package/fibers.md) ^1.0.5

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.2.5 (latest) — 2015-07-23
- 0.2.2 — 2014-05-27
- 0.2.1 — 2014-05-19
- 0.2.0 — 2014-05-18

## README

# Hi, this is ascs
- - -
**ascs ==> as cs ==> `AS CSharp`.**

A small library provides the C# liked async/await style to Node.js/io.js.

I'm maybe reinventing the wheel again. :smile:

Just for fun and enjoy coding.

# Use

Only **3** API in **ascs**:

+ **ascs.env**    Create a **async** environment to execute the process
+ **ascs.conv**   try to convert your callback style function to ASCSFunction (*your callback must be the last argument*)
+ **ascs.await**  a helper function. equal to: `ascs.await(f(1,2))` => `var t = f(1,2); t.await(); t.result`

# Easy Demo
- - -
```javascript
var myfun = function(tips, cb)  {
    console.log(tips, 'start');
    setTimeout(function () {
        console.log('Function is done');
        cb(1,2,3,4,5);
    }, 3000);
    console.log(tips, 'end');
}

ascs.env(function() {
    var i = 0;
    var myfun_async = ascs.conv(myfun);
    console.log('current is:', i++);        // 0
    var task = myfun_async('Hello world');
    console.log('current is:', i++);        // 1
    task.await();
    console.log('current is:', i++);        // 2
    console.log('The result is:', task.result);
    console.log('current is:', i++);        // 3
})();

```

run this code. the console will output these:
```
current is: 0
Hello world start
Hello world end
current is: 1
Function is done
current is: 2
The result is: { '0': 1, '1': 2, '2': 3, '3': 4, '4': 5 }
current is: 3
```
The process will be waiting the task until it has finished

Now, let's remove the `task.await()`. the output will become:
```
current is: 0
Hello world start
Hello world end
current is: 1
current is: 2
The result is: null
current is: 3
Function is done
```

The process in `ascs.env` will not be stopped. but `myfun` is also run asynchronously.

# Roadmap
- - -
1. Exception *(0.2.5)*
2. Debug *(0.2.5)*

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