k2hash 1.1.34 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +106 -0
- package/build/cjs/index.js +296 -0
- package/build/esm/index.js +293 -0
- package/buildutils/make_node_prebuild_variables.sh +359 -0
- package/buildutils/node_prebuild.sh +371 -0
- package/buildutils/node_prebuild_install.sh +307 -0
- package/index.js +4 -1
- package/index.mjs +154 -0
- package/package.json +76 -20
- package/src/index.ts +378 -0
- package/src/k2h_cbs.cc +27 -41
- package/src/k2h_cbs.h +17 -13
- package/src/k2h_common.h +1 -1
- package/src/k2h_keyqueue.cc +513 -339
- package/src/k2h_keyqueue.h +38 -30
- package/src/k2h_keyqueue_async.h +222 -184
- package/src/k2h_queue.cc +483 -304
- package/src/k2h_queue.h +38 -30
- package/src/k2h_queue_async.h +218 -173
- package/src/k2h_shm.cc +1963 -1221
- package/src/k2h_shm.h +109 -104
- package/src/k2h_shm_async.h +721 -564
- package/src/k2hash.cc +22 -8
- package/src/k2hkeyqueue.cc +21 -8
- package/src/k2hqueue.cc +21 -8
- package/types/index.d.ts +570 -0
- package/ChangeLog +0 -137
- package/src/binding.gyp +0 -146
package/src/k2h_queue.h
CHANGED
|
@@ -27,47 +27,55 @@
|
|
|
27
27
|
//---------------------------------------------------------
|
|
28
28
|
// K2hQueue Class
|
|
29
29
|
//---------------------------------------------------------
|
|
30
|
-
class K2hQueue : public
|
|
30
|
+
class K2hQueue : public Napi::ObjectWrap<K2hQueue>
|
|
31
31
|
{
|
|
32
32
|
friend class K2hNode;
|
|
33
33
|
|
|
34
34
|
public:
|
|
35
|
-
static void Init(
|
|
36
|
-
static
|
|
37
|
-
static
|
|
35
|
+
static void Init(Napi::Env env, Napi::Object exports);
|
|
36
|
+
static Napi::Object NewInstance(Napi::Env env);
|
|
37
|
+
static Napi::Object NewInstance(Napi::Env env, const Napi::Value& arg);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
static Napi::Object GetInstance(const Napi::CallbackInfo& info);
|
|
40
|
+
|
|
41
|
+
// Constructor / Destructor
|
|
42
|
+
explicit K2hQueue(const Napi::CallbackInfo& info);
|
|
41
43
|
~K2hQueue();
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
private:
|
|
46
|
+
Napi::Value New(const Napi::CallbackInfo& info);
|
|
47
|
+
|
|
48
|
+
Napi::Value On(const Napi::CallbackInfo& info);
|
|
49
|
+
Napi::Value OnPush(const Napi::CallbackInfo& info);
|
|
50
|
+
Napi::Value OnPop(const Napi::CallbackInfo& info);
|
|
51
|
+
Napi::Value OnCount(const Napi::CallbackInfo& info);
|
|
52
|
+
Napi::Value OnRead(const Napi::CallbackInfo& info);
|
|
53
|
+
Napi::Value OnRemove(const Napi::CallbackInfo& info);
|
|
44
54
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
Napi::Value Off(const Napi::CallbackInfo& info);
|
|
56
|
+
Napi::Value OffPush(const Napi::CallbackInfo& info);
|
|
57
|
+
Napi::Value OffPop(const Napi::CallbackInfo& info);
|
|
58
|
+
Napi::Value OffCount(const Napi::CallbackInfo& info);
|
|
59
|
+
Napi::Value OffRead(const Napi::CallbackInfo& info);
|
|
60
|
+
Napi::Value OffRemove(const Napi::CallbackInfo& info);
|
|
61
|
+
|
|
62
|
+
Napi::Value Initialize(const Napi::CallbackInfo& info);
|
|
63
|
+
Napi::Value IsEmpty(const Napi::CallbackInfo& info);
|
|
64
|
+
Napi::Value Count(const Napi::CallbackInfo& info);
|
|
65
|
+
Napi::Value Read(const Napi::CallbackInfo& info);
|
|
66
|
+
Napi::Value Push(const Napi::CallbackInfo& info);
|
|
67
|
+
Napi::Value Pop(const Napi::CallbackInfo& info);
|
|
68
|
+
Napi::Value Remove(const Napi::CallbackInfo& info);
|
|
69
|
+
Napi::Value Dump(const Napi::CallbackInfo& info);
|
|
70
|
+
|
|
71
|
+
public:
|
|
72
|
+
// constructor reference
|
|
73
|
+
static Napi::FunctionReference constructor;
|
|
57
74
|
|
|
58
|
-
|
|
59
|
-
static NAN_METHOD(IsEmpty);
|
|
60
|
-
static NAN_METHOD(Count);
|
|
61
|
-
static NAN_METHOD(Read);
|
|
62
|
-
static NAN_METHOD(Push);
|
|
63
|
-
static NAN_METHOD(Pop);
|
|
64
|
-
static NAN_METHOD(Remove);
|
|
65
|
-
static NAN_METHOD(Dump);
|
|
75
|
+
StackEmitCB _cbs;
|
|
66
76
|
|
|
67
77
|
private:
|
|
68
|
-
|
|
69
|
-
K2HQueue _k2hqueue;
|
|
70
|
-
StackEmitCB _cbs;
|
|
78
|
+
K2HQueue _k2hqueue;
|
|
71
79
|
};
|
|
72
80
|
|
|
73
81
|
#endif
|
package/src/k2h_queue_async.h
CHANGED
|
@@ -34,69 +34,76 @@
|
|
|
34
34
|
// Callback function: function(string error)
|
|
35
35
|
//
|
|
36
36
|
//---------------------------------------------------------
|
|
37
|
-
class
|
|
37
|
+
class K2hqPushAsyncWorker : public Napi::AsyncWorker
|
|
38
38
|
{
|
|
39
39
|
public:
|
|
40
|
-
|
|
40
|
+
K2hqPushAsyncWorker(const Napi::Function& callback, K2HQueue* pobj, const char* pdata, const char* ppass, const time_t* pexpire) :
|
|
41
|
+
Napi::AsyncWorker(callback), _callbackRef(Napi::Persistent(callback)), _pk2hqobj(pobj), _is_data_set(nullptr != pdata), _strdata(pdata ? pdata : ""), _is_pass_set(nullptr != ppass), _strpass(ppass ? ppass : ""), _expire(pexpire ? *pexpire : 0)
|
|
41
42
|
{
|
|
42
|
-
|
|
43
|
-
is_pass_set = (NULL != ppass);
|
|
43
|
+
_callbackRef.Ref();
|
|
44
44
|
}
|
|
45
|
-
~K2hqPushWorker() {}
|
|
46
45
|
|
|
47
|
-
|
|
46
|
+
~K2hqPushAsyncWorker()
|
|
48
47
|
{
|
|
49
|
-
if(
|
|
50
|
-
|
|
48
|
+
if(_callbackRef){
|
|
49
|
+
_callbackRef.Unref();
|
|
50
|
+
_callbackRef.Reset();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Runs on worker thread
|
|
55
|
+
void Execute() override
|
|
56
|
+
{
|
|
57
|
+
if(!_pk2hqobj){
|
|
58
|
+
SetError("No object is associated to async worker");
|
|
51
59
|
return;
|
|
52
60
|
}
|
|
53
|
-
if(!
|
|
54
|
-
|
|
61
|
+
if(!_is_data_set){
|
|
62
|
+
SetError("Specified data is empty(null)");
|
|
55
63
|
return;
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
// push
|
|
59
|
-
if(!
|
|
60
|
-
|
|
61
|
-
|
|
67
|
+
if(!_pk2hqobj->Push(reinterpret_cast<const unsigned char*>(_strdata.c_str()), (_strdata.length() + 1), NULL, (_is_pass_set ? _strpass.c_str() : NULL), (_expire > 0 ? &_expire : NULL))){
|
|
68
|
+
SetError("Failed to push data for k2hqueue.");
|
|
69
|
+
return;
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
|
|
65
|
-
|
|
73
|
+
// handler for success
|
|
74
|
+
void OnOK() override
|
|
66
75
|
{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
v8::Local<v8::Value> argv[argc] = { Nan::Null() };
|
|
76
|
+
Napi::Env env = Env();
|
|
77
|
+
Napi::HandleScope scope(env);
|
|
70
78
|
|
|
71
|
-
if(
|
|
72
|
-
|
|
79
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
80
|
+
_callbackRef.Call({ env.Null() });
|
|
73
81
|
}else{
|
|
74
|
-
|
|
75
|
-
return;
|
|
82
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
85
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
// handler for failure (by calling SetError)
|
|
87
|
+
void OnError(const Napi::Error& err) override
|
|
88
|
+
{
|
|
89
|
+
Napi::Env env = Env();
|
|
90
|
+
Napi::HandleScope scope(env);
|
|
84
91
|
|
|
85
|
-
if(
|
|
86
|
-
|
|
92
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
93
|
+
_callbackRef.Call({ Napi::String::New(env, err.Message()) });
|
|
87
94
|
}else{
|
|
88
|
-
|
|
89
|
-
return;
|
|
95
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
90
96
|
}
|
|
91
|
-
|
|
97
|
+
}
|
|
92
98
|
|
|
93
99
|
private:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
Napi::FunctionReference _callbackRef;
|
|
101
|
+
K2HQueue* _pk2hqobj;
|
|
102
|
+
bool _is_data_set;
|
|
103
|
+
std::string _strdata;
|
|
104
|
+
bool _is_pass_set;
|
|
105
|
+
std::string _strpass;
|
|
106
|
+
time_t _expire;
|
|
100
107
|
};
|
|
101
108
|
|
|
102
109
|
//---------------------------------------------------------
|
|
@@ -106,59 +113,66 @@ class K2hqPushWorker : public Nan::AsyncWorker
|
|
|
106
113
|
// Callback function: function(string error, int count)
|
|
107
114
|
//
|
|
108
115
|
//---------------------------------------------------------
|
|
109
|
-
class
|
|
116
|
+
class K2hqCountAsyncWorker : public Napi::AsyncWorker
|
|
110
117
|
{
|
|
111
118
|
public:
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
K2hqCountAsyncWorker(const Napi::Function& callback, K2HQueue* pobj) :
|
|
120
|
+
Napi::AsyncWorker(callback), _callbackRef(Napi::Persistent(callback)), _pk2hqobj(pobj), _rescount(0)
|
|
121
|
+
{
|
|
122
|
+
_callbackRef.Ref();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
~K2hqCountAsyncWorker()
|
|
126
|
+
{
|
|
127
|
+
if(_callbackRef){
|
|
128
|
+
_callbackRef.Unref();
|
|
129
|
+
_callbackRef.Reset();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
114
132
|
|
|
115
|
-
|
|
133
|
+
// Runs on worker thread
|
|
134
|
+
void Execute() override
|
|
116
135
|
{
|
|
117
|
-
if(
|
|
118
|
-
|
|
136
|
+
if(NULL == _pk2hqobj){
|
|
137
|
+
// Report an error so OnError will be invoked.
|
|
138
|
+
SetError("No object is associated to async worker");
|
|
119
139
|
return;
|
|
120
140
|
}
|
|
121
141
|
|
|
122
142
|
// count
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
// [NOTE]
|
|
126
|
-
// This execution does not return error at any case.
|
|
143
|
+
_rescount = static_cast<int>(_pk2hqobj->GetCount());
|
|
127
144
|
}
|
|
128
145
|
|
|
129
|
-
|
|
146
|
+
// handler for success
|
|
147
|
+
void OnOK() override
|
|
130
148
|
{
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
v8::Local<v8::Value> argv[argc] = { Nan::Null(), Nan::New(rescount) };
|
|
149
|
+
Napi::Env env = Env();
|
|
150
|
+
Napi::HandleScope scope(env);
|
|
134
151
|
|
|
135
|
-
if(
|
|
136
|
-
|
|
152
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
153
|
+
_callbackRef.Call({ env.Null(), Napi::Number::New(env, _rescount) });
|
|
137
154
|
}else{
|
|
138
|
-
|
|
139
|
-
return;
|
|
155
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
140
156
|
}
|
|
141
157
|
}
|
|
142
158
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const int argc = 1;
|
|
149
|
-
v8::Local<v8::Value> argv[argc] = { Nan::New<v8::String>(this->ErrorMessage()).ToLocalChecked() };
|
|
159
|
+
// handler for failure (by calling SetError)
|
|
160
|
+
void OnError(const Napi::Error& err) override
|
|
161
|
+
{
|
|
162
|
+
Napi::Env env = Env();
|
|
163
|
+
Napi::HandleScope scope(env);
|
|
150
164
|
|
|
151
|
-
if(
|
|
152
|
-
|
|
165
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
166
|
+
_callbackRef.Call({ Napi::String::New(env, err.Message()) });
|
|
153
167
|
}else{
|
|
154
|
-
|
|
155
|
-
return;
|
|
168
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
156
169
|
}
|
|
157
|
-
|
|
170
|
+
}
|
|
158
171
|
|
|
159
172
|
private:
|
|
160
|
-
|
|
161
|
-
|
|
173
|
+
Napi::FunctionReference _callbackRef;
|
|
174
|
+
K2HQueue* _pk2hqobj;
|
|
175
|
+
int _rescount;
|
|
162
176
|
};
|
|
163
177
|
|
|
164
178
|
//---------------------------------------------------------
|
|
@@ -168,71 +182,81 @@ class K2hqCountWorker : public Nan::AsyncWorker
|
|
|
168
182
|
// Callback function: function(string error[, string data])
|
|
169
183
|
//
|
|
170
184
|
//---------------------------------------------------------
|
|
171
|
-
class
|
|
185
|
+
class K2hqReadAsyncWorker : public Napi::AsyncWorker
|
|
172
186
|
{
|
|
173
187
|
public:
|
|
174
|
-
|
|
175
|
-
|
|
188
|
+
K2hqReadAsyncWorker(const Napi::Function& callback, K2HQueue* pobj, int pos, const char* ppass) :
|
|
189
|
+
Napi::AsyncWorker(callback), _callbackRef(Napi::Persistent(callback)), _pk2hqobj(pobj), _getpos(pos), _is_pass_set(NULL != ppass), _strpass(ppass ? ppass : ""), _resdata()
|
|
190
|
+
{
|
|
191
|
+
_callbackRef.Ref();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
~K2hqReadAsyncWorker()
|
|
195
|
+
{
|
|
196
|
+
if(_callbackRef){
|
|
197
|
+
_callbackRef.Unref();
|
|
198
|
+
_callbackRef.Reset();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
176
201
|
|
|
177
|
-
|
|
202
|
+
// Runs on worker thread
|
|
203
|
+
void Execute() override
|
|
178
204
|
{
|
|
179
|
-
if(
|
|
180
|
-
|
|
205
|
+
if(NULL == _pk2hqobj){
|
|
206
|
+
SetError("No object is associated to async worker");
|
|
181
207
|
return;
|
|
182
208
|
}
|
|
183
|
-
if(
|
|
184
|
-
|
|
209
|
+
if(_getpos < 0){
|
|
210
|
+
SetError("Specified position is under zero.");
|
|
185
211
|
return;
|
|
186
212
|
}
|
|
187
213
|
|
|
188
214
|
// read
|
|
189
215
|
unsigned char* pdata = NULL;
|
|
190
216
|
size_t datalen = 0;
|
|
191
|
-
bool result =
|
|
217
|
+
bool result = _pk2hqobj->Read(&pdata, datalen, _getpos, (_is_pass_set ? _strpass.c_str() : NULL));
|
|
192
218
|
if(!result || !pdata || 0 == datalen){
|
|
193
|
-
|
|
194
|
-
this->SetErrorMessage("Failed to read data for k2hqueue.");
|
|
219
|
+
SetError("Failed to read data for k2hqueue.");
|
|
195
220
|
}else{
|
|
196
|
-
|
|
197
|
-
resdata = std::string(reinterpret_cast<const char*>(pdata), datalen);
|
|
221
|
+
_resdata.assign(reinterpret_cast<const char*>(pdata), static_cast<size_t>(strlen(reinterpret_cast<const char*>(pdata))));
|
|
198
222
|
}
|
|
199
223
|
K2H_Free(pdata);
|
|
200
224
|
}
|
|
201
225
|
|
|
202
|
-
|
|
226
|
+
// handler for success
|
|
227
|
+
void OnOK() override
|
|
203
228
|
{
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
v8::Local<v8::Value> argv[argc] = { Nan::Null(), Nan::New<v8::String>(resdata.c_str()).ToLocalChecked() };
|
|
229
|
+
Napi::Env env = Env();
|
|
230
|
+
Napi::HandleScope scope(env);
|
|
207
231
|
|
|
208
|
-
if(
|
|
209
|
-
|
|
232
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
233
|
+
Napi::String val = Napi::String::New(env, _resdata.c_str(), static_cast<size_t>(strlen(_resdata.c_str())));
|
|
234
|
+
_callbackRef.Call({ env.Null(), val });
|
|
210
235
|
}else{
|
|
211
|
-
|
|
212
|
-
return;
|
|
236
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
213
237
|
}
|
|
214
238
|
}
|
|
215
239
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
240
|
+
// handler for failure (by calling SetError)
|
|
241
|
+
void OnError(const Napi::Error& err) override
|
|
242
|
+
{
|
|
243
|
+
Napi::Env env = Env();
|
|
244
|
+
Napi::HandleScope scope(env);
|
|
221
245
|
|
|
222
|
-
if(
|
|
223
|
-
|
|
246
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
247
|
+
_callbackRef.Call({ Napi::String::New(env, err.Message()) });
|
|
224
248
|
}else{
|
|
225
|
-
|
|
226
|
-
return;
|
|
249
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
227
250
|
}
|
|
228
|
-
|
|
251
|
+
}
|
|
229
252
|
|
|
230
253
|
private:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
std::string
|
|
254
|
+
Napi::FunctionReference _callbackRef;
|
|
255
|
+
K2HQueue* _pk2hqobj;
|
|
256
|
+
int _getpos;
|
|
257
|
+
bool _is_pass_set;
|
|
258
|
+
std::string _strpass;
|
|
259
|
+
std::string _resdata;
|
|
236
260
|
};
|
|
237
261
|
|
|
238
262
|
//---------------------------------------------------------
|
|
@@ -242,66 +266,76 @@ class K2hqReadWorker : public Nan::AsyncWorker
|
|
|
242
266
|
// Callback function: function(string error[, string data])
|
|
243
267
|
//
|
|
244
268
|
//---------------------------------------------------------
|
|
245
|
-
class
|
|
269
|
+
class K2hqPopAsyncWorker : public Napi::AsyncWorker
|
|
246
270
|
{
|
|
247
271
|
public:
|
|
248
|
-
|
|
249
|
-
|
|
272
|
+
K2hqPopAsyncWorker(const Napi::Function& callback, K2HQueue* pobj, const char* ppass) :
|
|
273
|
+
Napi::AsyncWorker(callback), _callbackRef(Napi::Persistent(callback)), _pk2hqobj(pobj), _is_pass_set(NULL != ppass), _strpass(ppass ? ppass : ""), _resdata()
|
|
274
|
+
{
|
|
275
|
+
_callbackRef.Ref();
|
|
276
|
+
}
|
|
250
277
|
|
|
251
|
-
|
|
278
|
+
~K2hqPopAsyncWorker()
|
|
252
279
|
{
|
|
253
|
-
if(
|
|
254
|
-
|
|
280
|
+
if(_callbackRef){
|
|
281
|
+
_callbackRef.Unref();
|
|
282
|
+
_callbackRef.Reset();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Runs on worker thread
|
|
287
|
+
void Execute() override
|
|
288
|
+
{
|
|
289
|
+
if(!_pk2hqobj){
|
|
290
|
+
SetError("No object is associated to async worker");
|
|
255
291
|
return;
|
|
256
292
|
}
|
|
257
293
|
|
|
258
294
|
// pop
|
|
259
295
|
unsigned char* pdata = NULL;
|
|
260
296
|
size_t datalen = 0;
|
|
261
|
-
bool result =
|
|
297
|
+
bool result = _pk2hqobj->Pop(&pdata, datalen, NULL, (_is_pass_set ? _strpass.c_str() : NULL));
|
|
262
298
|
if(!result || !pdata || 0 == datalen){
|
|
263
|
-
|
|
264
|
-
this->SetErrorMessage("Failed to pop data for k2hqueue.");
|
|
299
|
+
SetError("Failed to pop data for k2hqueue.");
|
|
265
300
|
}else{
|
|
266
|
-
|
|
267
|
-
resdata = std::string(reinterpret_cast<const char*>(pdata), datalen);
|
|
301
|
+
_resdata.assign(reinterpret_cast<const char*>(pdata), static_cast<size_t>(strlen(reinterpret_cast<const char*>(pdata))));
|
|
268
302
|
}
|
|
269
303
|
K2H_Free(pdata);
|
|
270
304
|
}
|
|
271
305
|
|
|
272
|
-
|
|
306
|
+
// handler for success
|
|
307
|
+
void OnOK() override
|
|
273
308
|
{
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
v8::Local<v8::Value> argv[argc] = { Nan::Null(), Nan::New<v8::String>(resdata.c_str()).ToLocalChecked() };
|
|
309
|
+
Napi::Env env = Env();
|
|
310
|
+
Napi::HandleScope scope(env);
|
|
277
311
|
|
|
278
|
-
if(
|
|
279
|
-
|
|
312
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
313
|
+
Napi::String val = Napi::String::New(env, _resdata.c_str(), static_cast<size_t>(strlen(_resdata.c_str())));
|
|
314
|
+
_callbackRef.Call({ env.Null(), val });
|
|
280
315
|
}else{
|
|
281
|
-
|
|
282
|
-
return;
|
|
316
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
283
317
|
}
|
|
284
318
|
}
|
|
285
319
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
320
|
+
// handler for failure (by calling SetError)
|
|
321
|
+
void OnError(const Napi::Error& err) override
|
|
322
|
+
{
|
|
323
|
+
Napi::Env env = Env();
|
|
324
|
+
Napi::HandleScope scope(env);
|
|
291
325
|
|
|
292
|
-
if(
|
|
293
|
-
|
|
326
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
327
|
+
_callbackRef.Call({ Napi::String::New(env, err.Message()) });
|
|
294
328
|
}else{
|
|
295
|
-
|
|
296
|
-
return;
|
|
329
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
297
330
|
}
|
|
298
|
-
|
|
331
|
+
}
|
|
299
332
|
|
|
300
333
|
private:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
std::string
|
|
334
|
+
Napi::FunctionReference _callbackRef;
|
|
335
|
+
K2HQueue* _pk2hqobj;
|
|
336
|
+
bool _is_pass_set;
|
|
337
|
+
std::string _strpass;
|
|
338
|
+
std::string _resdata;
|
|
305
339
|
};
|
|
306
340
|
|
|
307
341
|
//---------------------------------------------------------
|
|
@@ -311,65 +345,76 @@ class K2hqPopWorker : public Nan::AsyncWorker
|
|
|
311
345
|
// Callback function: function(string error[, int removed_queue_count])
|
|
312
346
|
//
|
|
313
347
|
//---------------------------------------------------------
|
|
314
|
-
class
|
|
348
|
+
class K2hqRemoveAsyncWorker : public Napi::AsyncWorker
|
|
315
349
|
{
|
|
316
350
|
public:
|
|
317
|
-
|
|
318
|
-
|
|
351
|
+
K2hqRemoveAsyncWorker(const Napi::Function& callback, K2HQueue* pobj, int count, const char* ppass) :
|
|
352
|
+
Napi::AsyncWorker(callback), _callbackRef(Napi::Persistent(callback)), _pk2hqobj(pobj), _rmcount(count), _is_pass_set(NULL != ppass), _strpass(ppass ? ppass : ""), _removed_count(0)
|
|
353
|
+
{
|
|
354
|
+
_callbackRef.Ref();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
~K2hqRemoveAsyncWorker()
|
|
358
|
+
{
|
|
359
|
+
if(_callbackRef){
|
|
360
|
+
_callbackRef.Unref();
|
|
361
|
+
_callbackRef.Reset();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
319
364
|
|
|
320
|
-
|
|
365
|
+
// Runs on worker thread
|
|
366
|
+
void Execute() override
|
|
321
367
|
{
|
|
322
|
-
if(!
|
|
323
|
-
|
|
368
|
+
if(!_pk2hqobj){
|
|
369
|
+
SetError("No object is associated to async worker");
|
|
324
370
|
return;
|
|
325
371
|
}
|
|
326
|
-
if(
|
|
327
|
-
|
|
372
|
+
if(_rmcount <= 0){
|
|
373
|
+
SetError("Specified remove count is under 1.");
|
|
328
374
|
return;
|
|
329
375
|
}
|
|
330
376
|
|
|
331
377
|
// remove
|
|
332
|
-
|
|
333
|
-
if(-1 ==
|
|
334
|
-
|
|
335
|
-
|
|
378
|
+
_removed_count = _pk2hqobj->Remove(_rmcount, NULL, NULL, (_is_pass_set ? _strpass.c_str() : NULL));
|
|
379
|
+
if(-1 == _removed_count){
|
|
380
|
+
SetError("Failed to remove queue for k2hqueue.");
|
|
381
|
+
return;
|
|
336
382
|
}
|
|
337
383
|
}
|
|
338
384
|
|
|
339
|
-
|
|
385
|
+
// handler for success
|
|
386
|
+
void OnOK() override
|
|
340
387
|
{
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
v8::Local<v8::Value> argv[argc] = { Nan::Null(), Nan::New(removed_count) };
|
|
388
|
+
Napi::Env env = Env();
|
|
389
|
+
Napi::HandleScope scope(env);
|
|
344
390
|
|
|
345
|
-
if(
|
|
346
|
-
|
|
391
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
392
|
+
_callbackRef.Call({ env.Null(), Napi::Number::New(env, static_cast<double>(_removed_count)) });
|
|
347
393
|
}else{
|
|
348
|
-
|
|
349
|
-
return;
|
|
394
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
350
395
|
}
|
|
351
396
|
}
|
|
352
397
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
398
|
+
// handler for failure (by calling SetError)
|
|
399
|
+
void OnError(const Napi::Error& err) override
|
|
400
|
+
{
|
|
401
|
+
Napi::Env env = Env();
|
|
402
|
+
Napi::HandleScope scope(env);
|
|
358
403
|
|
|
359
|
-
if(
|
|
360
|
-
|
|
404
|
+
if(_callbackRef && _callbackRef.Value().IsFunction()){
|
|
405
|
+
_callbackRef.Call({ Napi::String::New(env, err.Message()) });
|
|
361
406
|
}else{
|
|
362
|
-
|
|
363
|
-
return;
|
|
407
|
+
Napi::TypeError::New(env, "Internal error in async worker").ThrowAsJavaScriptException();
|
|
364
408
|
}
|
|
365
|
-
|
|
409
|
+
}
|
|
366
410
|
|
|
367
411
|
private:
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
412
|
+
Napi::FunctionReference _callbackRef;
|
|
413
|
+
K2HQueue* _pk2hqobj;
|
|
414
|
+
int _rmcount;
|
|
415
|
+
bool _is_pass_set;
|
|
416
|
+
std::string _strpass;
|
|
417
|
+
int _removed_count;
|
|
373
418
|
};
|
|
374
419
|
|
|
375
420
|
#endif
|