Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ts-simple-event-bus

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ts-simple-event-bus - npm Package Compare versions

Comparing version 1.1.3 to 1.1.4

5

package.json
{
"name": "ts-simple-event-bus",
"version": "1.1.3",
"version": "1.1.4",
"main": "dist/index.js",

@@ -11,3 +11,4 @@ "types": "dist/index.d.ts",

"test": "nyc mocha -r ts-node/register **/**/*.test.ts",
"coverage": "nyc report --reporter=text-lcov | coveralls"
"coverage": "nyc report --reporter=text-lcov | coveralls",
"publish": "yarn build && npm publish"
},

@@ -14,0 +15,0 @@ "author": "Hugo LAPLACE-BUILHE",

@@ -76,2 +76,26 @@ import chai from "chai";

});
it("Can handle Promise response", async () => {
const bus = new EventBus(idGenerator);
const responseQueueName = "event-response";
bus.subscribe({
queue: "event-request",
callback: (msg, id) => {
return new Promise((req, rej) => {
const timeoutId = setTimeout(() => {
bus.publish({ queue: responseQueueName, message: { truc: "response" }, id });
req();
clearTimeout(timeoutId);
}, 1000);
});
},
});
const result = await bus.publishAndWaitForResponse({
queue: "event-request",
responseQueue: responseQueueName,
message: { truc: "request" },
timeout: 2000,
});
expect(result).to.deep.equal({ truc: "response" });
});
});

8

src/bus.ts

@@ -11,3 +11,3 @@ type Queue = string;

export type Callback<T> = (message: Message<T>, id?: string) => void;
export type Callback<T> = (message: Message<T>, id?: string) => void | Promise<void>;

@@ -30,6 +30,6 @@ export type IdGenerator = () => string;

publish<T>({ queue, message, id }: { queue: Queue; message: Message<T>; id?: string }) {
this.subcriptions.forEach((sub) => {
async publish<T>({ queue, message, id }: { queue: Queue; message: Message<T>; id?: string }) {
await this.subcriptions.forEach(async (sub) => {
if (sub.queue === queue) {
sub.callback(message, id);
await sub.callback(message, id);
}

@@ -36,0 +36,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc