https://github.com/jcoreio/web-streams-finally
https://github.com/jcoreio/web-streams-finally
Last synced: 10 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jcoreio/web-streams-finally
- Owner: jcoreio
- License: mit
- Created: 2024-11-04T17:01:48.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-14T19:20:29.000Z (about 1 year ago)
- Last Synced: 2025-04-14T20:28:46.032Z (about 1 year ago)
- Language: TypeScript
- Size: 206 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @jcoreio/web-streams-finally
userland implementation of proposed finally() API for web streams
[](https://circleci.com/gh/jcoreio/web-streams-finally)
[](https://codecov.io/gh/jcoreio/web-streams-finally)
[](https://github.com/semantic-release/semantic-release)
[](https://badge.fury.io/js/%40jcoreio%2Fweb-streams-finally)
## `ReadableStreamWithFinally`
```ts
import { ReadableStreamWithFinally } from '@jcoreio/web-streams-finally'
const stream = new ReadableStreamWithFinally({
async pull(controller) {
...
},
async finally(why: 'close' | 'cancel' | 'error', reason?: any) {
// this will be called when the stream is closed, canceled, or errored
}
})
```
## `ReadableStreamWithSignal`
```ts
import { ReadableStreamWithSignal } from '@jcoreio/web-streams-finally'
const stream = new ReadableStreamWithSignal({
async pull(controller) {
await doSomething({
signal: controller.signal, // will be aborted when stream errors is closed, canceled, or errored
})
...
},
async finally(why: 'close' | 'cancel' | 'error', reason?: any) {
// this will be called when the stream is closed, canceled, or errored
}
})
```
## `WritableStreamWithFinally`
```ts
import { WritableStreamWithFinally } from '@jcoreio/web-streams-finally'
const stream = new WritableStreamWithFinally({
async write(controller) {
...
},
async finally(why: 'close' | 'abort' | 'error', reason?: any) {
// this will be called when the stream is closed, aborted, or errored
}
})
```