ts-simple-event-bus
Advanced tools
Comparing version 1.1.1 to 1.1.2
declare type Queue = string; | ||
export declare type Message<T = any> = { | ||
id: string; | ||
} & T; | ||
export declare type Message<T = any> = T; | ||
export declare type Subscription<T> = { | ||
@@ -10,13 +8,26 @@ id: string; | ||
}; | ||
export declare type Callback<T> = (message: Message<T>) => void; | ||
export declare type Callback<T> = (message: Message<T>, id?: string) => void; | ||
export declare type IdGenerator = () => string; | ||
export declare class MessageTimeoutError extends Error { | ||
constructor(message?: Message); | ||
} | ||
export declare class EventBus { | ||
private subcriptions; | ||
private idGenerator; | ||
constructor(idGenerator: () => string); | ||
publish(queue: Queue, message: Message): void; | ||
constructor(idGenerator: IdGenerator); | ||
publish<T>({ queue, message, id }: { | ||
queue: Queue; | ||
message: Message<T>; | ||
id?: string; | ||
}): void; | ||
subscribe<T = any>(subscription: Omit<Subscription<T>, "id">): { | ||
unsubscribe: () => void; | ||
}; | ||
publishAndWaitForResponse<Req, Rep>({ message, queue, responseQueue, timeout, }: { | ||
queue: Queue; | ||
responseQueue: string; | ||
message: Message<Req>; | ||
timeout?: number; | ||
}): Promise<Rep>; | ||
} | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["ts-event-bus"]=t():e["ts-event-bus"]=t()}(self,(function(){return(()=>{"use strict";var e={225:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventBus=void 0,t.EventBus=class{constructor(e){this.subcriptions=[],this.idGenerator=e}publish(e,t){this.subcriptions.every((r=>{r.queue===e&&r.callback(t)}))}subscribe(e){const t=this.idGenerator();return this.subcriptions.push(Object.assign(Object.assign({},e),{id:t})),{unsubscribe:()=>{this.subcriptions=this.subcriptions.filter((e=>e.id!==t))}}}}},607:function(e,t,r){var s=this&&this.__createBinding||(Object.create?function(e,t,r,s){void 0===s&&(s=r),Object.defineProperty(e,s,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,s){void 0===s&&(s=r),e[s]=t[r]}),i=this&&this.__exportStar||function(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||s(t,e,r)};Object.defineProperty(t,"__esModule",{value:!0}),i(r(225),t)}},t={};return function r(s){var i=t[s];if(void 0!==i)return i.exports;var n=t[s]={exports:{}};return e[s].call(n.exports,n,n.exports,r),n.exports}(607)})()})); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["ts-event-bus"]=t():e["ts-event-bus"]=t()}(self,(function(){return(()=>{"use strict";var e={225:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.EventBus=t.MessageTimeoutError=void 0;class s extends Error{constructor(e){super("Message timeout error"),this.message=`Message timeout error on message ${e}`}}t.MessageTimeoutError=s,t.EventBus=class{constructor(e){this.subcriptions=[],this.idGenerator=e}publish({queue:e,message:t,id:s}){this.subcriptions.forEach((r=>{r.queue===e&&r.callback(t,s)}))}subscribe(e){const t=this.idGenerator();return this.subcriptions.push(Object.assign(Object.assign({},e),{id:t})),{unsubscribe:()=>{this.subcriptions=this.subcriptions.filter((e=>e.id!==t))}}}publishAndWaitForResponse({message:e,queue:t,responseQueue:r,timeout:i=5e3}){return new Promise(((o,u)=>{const n=this.idGenerator(),c=setTimeout((()=>{u(new s)}),i);this.subscribe({queue:r,callback:(e,t)=>{t===n&&(clearTimeout(c),o(e))}}),this.publish({queue:t,message:e,id:n})}))}}},607:function(e,t,s){var r=this&&this.__createBinding||(Object.create?function(e,t,s,r){void 0===r&&(r=s),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[s]}})}:function(e,t,s,r){void 0===r&&(r=s),e[r]=t[s]}),i=this&&this.__exportStar||function(e,t){for(var s in e)"default"===s||Object.prototype.hasOwnProperty.call(t,s)||r(t,e,s)};Object.defineProperty(t,"__esModule",{value:!0}),i(s(225),t)}},t={};return function s(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r].call(o.exports,o,o.exports,s),o.exports}(607)})()})); |
{ | ||
"name": "ts-simple-event-bus", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12030
236