diff options
author | Mike Morris <mikemorris@users.noreply.github.com> | 2016-07-12 18:37:28 -0400 |
---|---|---|
committer | Mike Morris <mikemorris@users.noreply.github.com> | 2016-07-13 00:02:14 -0400 |
commit | 871152832a941d7acfea0f37e45d69dd9bb60abb (patch) | |
tree | e0506d536dc5d422f7879eb9a402c00d966fc5bb | |
parent | 9af3de60262b99c25b83b5e7ea25df1e72c4d2db (diff) | |
download | qtlocation-mapboxgl-871152832a941d7acfea0f37e45d69dd9bb60abb.tar.gz |
[node] NodeRequest inherits from Nan::AsyncWorker
-rw-r--r-- | platform/node/src/node_request.cpp | 33 | ||||
-rw-r--r-- | platform/node/src/node_request.hpp | 16 |
2 files changed, 23 insertions, 26 deletions
diff --git a/platform/node/src/node_request.cpp b/platform/node/src/node_request.cpp index fa560ed4e7..5f2460ff7f 100644 --- a/platform/node/src/node_request.cpp +++ b/platform/node/src/node_request.cpp @@ -3,12 +3,22 @@ #include <mbgl/util/chrono.hpp> #include <cmath> -#include <iostream> namespace node_mbgl { -//////////////////////////////////////////////////////////////////////////////////////////////// -// Static Node Methods +NodeRequest::NodeRequest(mbgl::FileSource::Callback callback_) + : AsyncWorker(nullptr), + callback(callback_) { +} + +NodeRequest::~NodeRequest() { + // When this object gets garbage collected, make sure that the + // AsyncRequest can no longer attempt to remove the callback function + // this object was holding (it can't be fired anymore). + if (asyncRequest) { + asyncRequest->request = nullptr; + } +} Nan::Persistent<v8::Function> NodeRequest::constructor; @@ -42,6 +52,8 @@ v8::Handle<v8::Object> NodeRequest::Create(const mbgl::Resource& resource, mbgl: return scope.Escape(instance); } +void NodeRequest::Execute() {} + NAN_METHOD(NodeRequest::Respond) { using Error = mbgl::Response::Error; @@ -126,9 +138,6 @@ NAN_METHOD(NodeRequest::Respond) { info.GetReturnValue().SetUndefined(); } -//////////////////////////////////////////////////////////////////////////////////////////////// -// Instance - NodeRequest::NodeAsyncRequest::NodeAsyncRequest(NodeRequest* request_) : request(request_) { assert(request); // Make sure the JS object has a pointer to this so that it can remove its pointer in the @@ -145,16 +154,4 @@ NodeRequest::NodeAsyncRequest::~NodeAsyncRequest() { } } -NodeRequest::NodeRequest(mbgl::FileSource::Callback callback_) - : callback(callback_) { } - -NodeRequest::~NodeRequest() { - // When this object gets garbage collected, make sure that the AsyncRequest can no longer - // attempt to remove the callback function this object was holding (it can't be fired anymore). - if (asyncRequest) { - asyncRequest->request = nullptr; - } -} - -} // namespace node_mbgl diff --git a/platform/node/src/node_request.hpp b/platform/node/src/node_request.hpp index 2d307a3f19..140f668aa0 100644 --- a/platform/node/src/node_request.hpp +++ b/platform/node/src/node_request.hpp @@ -11,21 +11,21 @@ namespace node_mbgl { -class NodeFileSource; -class NodeRequest; - -class NodeRequest : public Nan::ObjectWrap { +class NodeRequest : public Nan::ObjectWrap, public Nan::AsyncWorker { public: + NodeRequest(mbgl::FileSource::Callback); + ~NodeRequest(); + + static Nan::Persistent<v8::Function> constructor; + static NAN_MODULE_INIT(Init); static NAN_METHOD(New); static NAN_METHOD(Respond); - static v8::Handle<v8::Object> Create(const mbgl::Resource&, mbgl::FileSource::Callback); - static Nan::Persistent<v8::Function> constructor; + void Execute(); - NodeRequest(mbgl::FileSource::Callback); - ~NodeRequest(); + static v8::Handle<v8::Object> Create(const mbgl::Resource&, mbgl::FileSource::Callback); struct NodeAsyncRequest : public mbgl::AsyncRequest { NodeAsyncRequest(NodeRequest*); |