Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lambdalisue/deno-workerio
🦕 Deno module to translate Worker's system of messages into ReadableStream and WritableStream
https://github.com/lambdalisue/deno-workerio
deno worker
Last synced: 2 days ago
JSON representation
🦕 Deno module to translate Worker's system of messages into ReadableStream and WritableStream
- Host: GitHub
- URL: https://github.com/lambdalisue/deno-workerio
- Owner: lambdalisue
- License: mit
- Created: 2021-02-27T08:49:30.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-30T00:14:26.000Z (3 months ago)
- Last Synced: 2024-10-10T16:50:53.588Z (24 days ago)
- Topics: deno, worker
- Language: TypeScript
- Homepage: https://jsr.io/@lambdalisue/workerio
- Size: 130 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# workerio
[![JSR](https://jsr.io/badges/@lambdalisue/workerio)](https://jsr.io/@lambdalisue/workerio)
[![Test](https://github.com/lambdalisue/deno-workerio/actions/workflows/test.yml/badge.svg)](https://github.com/lambdalisue/deno-workerio/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/lambdalisue/deno-workerio/graph/badge.svg?token=6Q1iOBg2Ka)](https://codecov.io/gh/lambdalisue/deno-workerio)[Deno][deno] module to translate Worker's system of messages into
[`ReadableStream`][readablestream] and
[`WritableStream`][writablestream].[deno]: https://deno.land/
[ReadableStream]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream
[WritableStream]: https://developer.mozilla.org/en-US/docs/Web/API/WritableStream## Example
#### Server
```typescript
import {
readableStreamFromWorker,
writableStreamFromWorker,
} from "@lambdalisue/workerio";const decoder = new TextDecoder();
const encoder = new TextEncoder();const worker = new Worker(new URL("./worker.ts", import.meta.url).href, {
type: "module",
});const reader = readableStreamFromWorker(worker);
const writer = writableStreamFromWorker(worker);
const w = writer.getWriter();await w.write(encoder.encode("Hello"));
await w.write(encoder.encode("World"));
w.releaseLock();for await (const data of reader) {
const text = decoder.decode(data);
console.log(text);
}
```#### Worker
```typescript
///
///import {
readableStreamFromWorker,
writableStreamFromWorker,
} from "@lambdalisue/workerio";const decoder = new TextDecoder();
const encoder = new TextEncoder();async function main(): Promise {
const reader = readableStreamFromWorker(self);
const writer = writableStreamFromWorker(self);
const w = writer.getWriter();for await (const data of reader) {
const text = decoder.decode(data);
await w.write(encoder.encode(`!!! ${text} !!!`));
}
w.releaseLock();
}main().catch((e) => console.error(e));
```## License
The code follows MIT license written in [LICENSE](./LICENSE). Contributors need
to agree that any modifications sent in this repository follow the license.