https://github.com/techquery/onion-stack
Middleware framework based on Async Generator of ECMAScript 2018, inspired by Koa 2
https://github.com/techquery/onion-stack
async-generator ecmascript koa middleware
Last synced: 9 months ago
JSON representation
Middleware framework based on Async Generator of ECMAScript 2018, inspired by Koa 2
- Host: GitHub
- URL: https://github.com/techquery/onion-stack
- Owner: TechQuery
- Created: 2019-03-04T15:29:35.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-09-02T19:13:23.000Z (over 1 year ago)
- Last Synced: 2025-03-28T18:50:57.586Z (9 months ago)
- Topics: async-generator, ecmascript, koa, middleware
- Language: TypeScript
- Homepage: https://tech-query.me/onion-stack/
- Size: 176 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: ReadMe.md
Awesome Lists containing this project
README
# OnionStack
**Middleware** framework based on [Async Generator][1] & [TypeScript][2], inspired by [Koa 2][3].
[][4]
[][5]
[][6]
[][7]
## Example
```javascript
import OnionStack from 'onion-stack';
const list = [];
const stack = new OnionStack(
function* () {
list.push(1);
yield;
list.push(2);
yield;
list.push(3);
},
async function* () {
await delay(0.1);
list.push(4);
yield;
list.push(5);
},
function () {
list.push(6);
}
);
stack.execute().then(() => console.log(list)); // [1, 4, 6, 5, 2]
```
[More cases](https://github.com/TechQuery/onion-stack/tree/master/test)
[1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of#Iterating_over_async_generators
[2]: https://www.typescriptlang.org
[3]: https://koajs.com
[4]: https://libraries.io/npm/onion-stack
[5]: https://github.com/TechQuery/onion-stack/actions/workflows/main.yml
[6]: https://www.jsdelivr.com/package/npm/onion-stack
[7]: https://nodei.co/npm/onion-stack/