Skip to content

Commit

Permalink
[fix] build issues, added mixing dependencies. (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal6792 authored Dec 28, 2023
1 parent 8c26482 commit 1526311
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,21 @@
"author": "Dhiway Engineering",
"license": "MIT",
"devDependencies": {
"@polkadot/api": "10.1.4",
"@subql/types": "latest",
"typescript": "^4.5.3",
"@polkadot/api": "10.1.4",
"@subql/cli": "latest",
"node-fetch": "^2.6.7",
"@subql/node": "latest",
"@subql/testing": "latest",
"@subql/node": "latest"
"@subql/types": "latest",
"node-fetch": "^2.7.0",
"typescript": "^4.9.5"
},
"resolutions": {
"ipfs-unixfs": "6.0.6"
},
"dependencies": {
"@polkadot/api-augment": "^10.11.2",
"@polkadot/types": "^10.11.2",
"@subql/types-core": "^0.4.0",
"tslib": "^2.6.2"
}
}
35 changes: 20 additions & 15 deletions src/handlers/utils/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
export type DispatcherHandler<T> = (data?: T) => Promise<void>
export type DispatcherHandler<T> = (data?: T) => Promise<void>;

export class Dispatcher<DispatchData> {
private subHandlers: Record<string, DispatcherHandler<DispatchData>[]> = {}
private subHandlers: Record<string, DispatcherHandler<DispatchData>[]> = {};

public regist (key: string, handler: DispatcherHandler<DispatchData>) {
if (Reflect.has(this.subHandlers, key) && typeof Array.isArray(this.subHandlers[key])) {
this.subHandlers[key].push(handler)
public regist(key: string, handler: DispatcherHandler<DispatchData>) {
if (
Reflect.has(this.subHandlers, key) &&
typeof Array.isArray(this.subHandlers[key])
) {
this.subHandlers[key].push(handler);
} else {
this.subHandlers[key] = [handler]
this.subHandlers[key] = [handler];
}
}

public batchRegist (list: { key: string; handler: DispatcherHandler<DispatchData> }[]) {
list.forEach((item) => this.regist(item.key, item.handler))
public batchRegist(
list: { key: string; handler: DispatcherHandler<DispatchData> }[]
) {
list.forEach((item) => this.regist(item.key, item.handler));
}

public async dispatch (key: string, data: DispatchData) {
const handlers = this.subHandlers[key]
public async dispatch(key: string, data: DispatchData) {
const handlers = this.subHandlers[key];

if (!handlers) return
if (!handlers) return;

await Promise.all(handlers.map((handler) => handler(data))).catch((e) => {
logger.info(e.stack.toString())
// logger.info(e.stack.toString())

throw e
})
throw e;
});
}
}
}

0 comments on commit 1526311

Please sign in to comment.