denosaurs / event Goto Github PK
View Code? Open in Web Editor NEW๐ Strictly typed event emitter with asynciterator support
Home Page: https://deno.land/x/event
License: MIT License
๐ Strictly typed event emitter with asynciterator support
Home Page: https://deno.land/x/event
License: MIT License
Hello!
I found your repo on JSR and I'm very impressed with it, especially with your use of Transform Streams. I started investigating using Transform Streams in my own work and I can't seem to get it working. Lmk if this issue should be moved somewhere else, I figured this was the best way to contact you.
import { assertEquals } from "jsr:@std/assert";
class DuplexStream<T> extends TransformStream<T, T> {}
Deno.test("Streams", async (t) => {
const stream = new DuplexStream<string>();
const expected = [
"Hello there",
"Here's some string data",
"All done",
];
await t.step("Writing", async () => {
const w = stream.writable.getWriter();
for await (const element of expected) {
await w.ready;
// Error: Promise resolution is still pending but the event loop has already resolved.
await w.write(element);
}
await w.ready;
w.releaseLock();
});
await t.step("Reading", async () => {
const r = stream.readable.values();
const actual = await Array.fromAsync(r);
assertEquals(actual, expected);
});
});
When running deno test
on the test case above, it responds with an error as soon as it hits await w.write(element);
:
error: Promise resolution is still pending but the event loop has already resolved.
Refactoring to use a WritableStream
only (test 2 below) or to pipe a ReadableStream
through (test 3 below) solves the error, but these approaches are undesirable. What am I doing wrong here? I've tried looking for guides on Transform Streams and consulting MDN's docs on them, and nothing has been helpful. I'm curious to see how you avoided the same errors in your own repo, because it seems inevitable given you use only a TransformStream
and don't use it as a pipe for any Readable Stream.
import { assertEquals } from "jsr:@std/assert";
Deno.test("Streams 2", async (t) => {
const collected: string[] = [];
const stream = new WritableStream<string>({
write(ch) {
collected.push(ch);
},
});
const expected = [
"Hello there",
"Here's some string data",
"All done",
];
await t.step("Writing", async () => {
const w = stream.getWriter();
for await (const element of expected) {
await w.ready;
await w.write(element);
}
await w.ready;
w.releaseLock();
});
await t.step("Reading", () => {
assertEquals(collected, expected);
});
});
import { assertEquals } from "jsr:@std/assert";
class DuplexStream<T> extends TransformStream<T, T> {}
Deno.test("Streams 3", async (t) => {
const stream = new DuplexStream<string>();
const expected = [
"Hello there",
"Here's some string data",
"All done",
];
await t.step("Writing & Reading", async () => {
const r = ReadableStream.from(expected).pipeThrough(stream).values();
const actual = await Array.fromAsync(r);
assertEquals(actual, expected);
});
});
Thanks so much for your time and for making such a high-quality library. I've starred this repo and hope to contribute to it when I can!
Hi, I'm trying to convert my first NodeJS project to deno.
EvenEmiter is a very common NodeJS feature, and I do not know how to convert event usage to NodeJS code with dnt.
Do you know how to do that?
I'm porting my deno.land/x module to JSR. However, while @denosaurs/event
name exists, nothing exists in the package.
When does it get pushed to JSR?
Hello!
I'm working on node_http, a Node.js-like HTTP server and I need to implement Server.close()
method. However, EventEmitter
already contains .close()
method.
My suggestion would be renaming .close()
to removeAllListeners()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.