Skip to content
Snippets Groups Projects
Commit 5bac478c authored by Marin Karamihalev's avatar Marin Karamihalev
Browse files

fixed isAsync bug on operate command

parent 578d8691
No related branches found
No related tags found
1 merge request!5Rebase with master
{ {
"name": "usp-js", "name": "usp-js",
"version": "0.3.4", "version": "0.3.5",
"description": "Helper library for easy usp communication using mqtt over tcp or ws.", "description": "Helper library for easy usp communication using mqtt over tcp or ws.",
"main": "node/index.js", "main": "node/index.js",
"browser": "web/index.js", "browser": "web/index.js",
......
...@@ -7,7 +7,8 @@ const make: MakeFn = ...@@ -7,7 +7,8 @@ const make: MakeFn =
(call, on): OperateRecipe => (call, on): OperateRecipe =>
async (path, opts) => { async (path, opts) => {
const Persistent = opts?.Persistent === undefined ? false : opts.Persistent; const Persistent = opts?.Persistent === undefined ? false : opts.Persistent;
const id = "NOTIFY@" + (opts?.ID || uniq(path)); const isAsync = !(opts && opts.isAsync === false);
const id = (isAsync ? "NOTIFY@" : "OPERATE@") + (opts?.ID || uniq(path));
const operateInput = { const operateInput = {
Enable: true, Enable: true,
ID: id, ID: id,
...@@ -18,11 +19,6 @@ const make: MakeFn = ...@@ -18,11 +19,6 @@ const make: MakeFn =
const commandKey = opts?.commandKey || ""; const commandKey = opts?.commandKey || "";
const newSubPath = await call("ADD", {
path: operateSubscriptionPath,
value: operateInput,
});
const command: OperateFn = (input) => { const command: OperateFn = (input) => {
return call( return call(
"OPERATE", "OPERATE",
...@@ -33,7 +29,7 @@ const make: MakeFn = ...@@ -33,7 +29,7 @@ const make: MakeFn =
resp: opts?.sendResponse ?? true, resp: opts?.sendResponse ?? true,
commandKey, commandKey,
}, },
opts && opts.isAsync === false ? {} : { responseMsgType: "NOTIFY" } isAsync ? { responseMsgType: "NOTIFY" } : {}
); );
}; };
...@@ -54,9 +50,17 @@ const make: MakeFn = ...@@ -54,9 +50,17 @@ const make: MakeFn =
}; };
}; };
const cleanup: OperateClearFn = () => call("DELETE", { paths: newSubPath }); if (isAsync) {
const newSubPath = await call("ADD", {
path: operateSubscriptionPath,
value: operateInput,
});
const cleanup: OperateClearFn = () =>
call("DELETE", { paths: newSubPath });
return [command, cleanup]; return [command, cleanup];
} else return [command, () => Promise.resolve()];
}; };
export default { export default {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment