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

@akiroz/pubsub-rpc

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@akiroz/pubsub-rpc - npm Package Compare versions

Comparing version 0.0.10 to 0.1.0

47

dist/main.js

@@ -62,3 +62,2 @@ "use strict";

exports.call = exports.defaultCallOptions = exports.register = void 0;
var events_1 = require("events");
var MsgPack = __importStar(require("@msgpack/msgpack"));

@@ -117,3 +116,3 @@ var dedupCache_1 = __importDefault(require("./dedupCache"));

return __awaiter(this, void 0, void 0, function () {
var id, strId, ee, responseTopic, msg, _a, result, error;
var id, strId, responseTopic, msg, _a, result, error;
var _this = this;

@@ -126,34 +125,22 @@ return __generator(this, function (_b) {

strId = util_1.encodeBase64URL(id);
ee = new events_1.EventEmitter();
responseTopic = topic + "/" + strId;
return [4 /*yield*/, Promise.race([
(function () { return __awaiter(_this, void 0, void 0, function () {
var _this = this;
return [4 /*yield*/, new Promise(function (rsov, rjct) {
setTimeout(function () {
client.unsubscribe(responseTopic);
rjct({ message: "timeout", data: { topic: topic, params: params, opt: opt, id: id } });
}, opt.timeout);
client
.subscribe(responseTopic, function (msg) { return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, client.subscribe(responseTopic, function (msg) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
return [2 /*return*/, void ee.emit("resp", msg)];
}); }); })];
case 1:
_a.sent();
client.publish(topic, MsgPack.encode({ id: id, params: params }));
return [4 /*yield*/, new Promise(function (rsov, rjct) {
return ee.once("resp", function (payload) {
client.unsubscribe(responseTopic);
rsov(payload);
});
})];
case 2: return [2 /*return*/, _a.sent()];
}
client.unsubscribe(responseTopic);
rsov(msg);
return [2 /*return*/];
});
}); })(),
new Promise(function (rsov, rjct) {
return setTimeout(function () {
client.unsubscribe(responseTopic);
rjct({ message: "timeout", data: { topic: topic, params: params, opt: opt, id: id } });
}, opt.timeout);
}),
])];
}); })
.then(function () {
client.publish(topic, MsgPack.encode({ id: id, params: params }));
});
})];
case 1:
msg = (_b.sent());
msg = _b.sent();
_a = MsgPack.decode(msg), result = _a.result, error = _a.error;

@@ -160,0 +147,0 @@ if (error)

{
"name": "@akiroz/pubsub-rpc",
"version": "0.0.10",
"version": "0.1.0",
"main": "dist/main.js",

@@ -12,4 +12,3 @@ "types": "dist/main.d.ts",

"dependencies": {
"@msgpack/msgpack": "^2.3.0",
"events": "^3.2.0"
"@msgpack/msgpack": "^2.3.0"
},

@@ -16,0 +15,0 @@ "devDependencies": {

@@ -1,2 +0,1 @@

import { EventEmitter } from "events";
import * as MsgPack from "@msgpack/msgpack";

@@ -61,22 +60,17 @@ import DedupCache from "./dedupCache";

const strId = encodeBase64URL(id);
const ee = new EventEmitter();
const responseTopic = `${topic}/${strId}`;
const msg = (await Promise.race([
(async () => {
await client.subscribe(responseTopic, async (msg) => void ee.emit("resp", msg));
client.publish(topic, MsgPack.encode({ id, params }));
return await new Promise((rsov, rjct) =>
ee.once("resp", (payload) => {
client.unsubscribe(responseTopic);
rsov(payload);
})
);
})(),
new Promise((rsov, rjct) =>
setTimeout(() => {
const msg = await new Promise<Uint8Array>((rsov, rjct) => {
setTimeout(() => {
client.unsubscribe(responseTopic);
rjct({ message: "timeout", data: { topic, params, opt, id } });
}, opt.timeout);
client
.subscribe(responseTopic, async (msg) => {
client.unsubscribe(responseTopic);
rjct({ message: "timeout", data: { topic, params, opt, id } });
}, opt.timeout)
),
])) as Uint8Array;
rsov(msg);
})
.then(() => {
client.publish(topic, MsgPack.encode({ id, params }));
});
});
const { result, error } = MsgPack.decode(msg) as RPCResponse;

@@ -83,0 +77,0 @@ if (error) throw error;

Sorry, the diff of this file is not supported yet

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