Skip to content

Commit 8162f7e

Browse files
committed
return err code on promise reject
1 parent 602bed3 commit 8162f7e

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

examples/async.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const snap7 = require("napi-snap7");
2+
3+
const client = new snap7.S7Client();
4+
5+
const time = (ms) => console.log("| Execution time : %d ms", ms);
6+
7+
const res = client.ConnectTo("192.168.57.12", 0, 1);
8+
9+
client.ReadArea(0x84, 510, 0, 100, 0x02, (err, data) => {
10+
if (err) return console.log(snap7.CliErrorText(err));
11+
console.log("Data", data);
12+
time(client.ExecTime());
13+
client.Disconnect();
14+
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"scripts": {
2222
"install": "node-gyp-build",
2323
"test": "echo \"Error: no test specified\"",
24-
"prebuild": "prebuildify --napi"
24+
"build": "prebuildify --napi"
2525
},
2626
"repository": {
2727
"type": "git",

prebuilds/linux-x64/node.napi.node

8 Bytes
Binary file not shown.

src/promise.h

+4-10
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,19 @@ class ReadPromiseWorker : public AsyncWorker
3232

3333
if (res != 0)
3434
{
35-
AsyncWorker::SetError("Error!");
35+
AsyncWorker::SetError("Eroor");
3636
}
3737
}
3838

3939
void OnOK()
4040
{
41-
if (res == 0)
42-
{
43-
deferred.Resolve(Buffer<uint8_t>::New(Env(), dataPtr, dataLength));
44-
}
45-
else
46-
{
47-
deferred.Resolve(Number::New(Env(), res));
48-
}
41+
deferred.Resolve(Buffer<uint8_t>::New(Env(), dataPtr, dataLength));
4942
}
5043

5144
void OnError(Error const &error)
5245
{
53-
deferred.Reject(error.Value());
46+
// deferred.Reject(error.Value());
47+
deferred.Reject(Number::New(Env(), res));
5448
}
5549

5650
Promise GetPromise() { return deferred.Promise(); }

0 commit comments

Comments
 (0)