@ 260528.1

231103.1 · 7f4a9ed91bbecb84e39f4bc8030247ce5116ddf8

Reorganize examples into categorized folders (#341)

* refactor: create directory structure to organize exmaples
* test: update test_all to work with new directory structure
* fix: bug in test_all if no package.json scripts
* test: cleanup output of test_all
* fix: remove default test script that throws from thread_safe_function_with_object_wrap
* fix: remove build_with_cmake from .gitignore
* fix: swith to ' from " and remove subdir from getAllTests call
* test: add extra test cases for npm start and just running the pkgJson.main with node
* refactor: move all examples to src directory
* refactor: add numbers to categories so they are ordered in the src folder
* refactor: simplify getAllExamples in test_all.js
* docs: add directory structure to README.md
* docs: update directory structure to README.md
* docs: update directory structure to README.md
* docs: update directory structure to README.md
* docs: update directory structure example in readme
* add back build_with_cmake --------- Co-authored-by: legendecas <legendecas@gmail.com>

reading declarations

Changes to src/5-async-work/async_pi_estimate/nan/async.cc. All files

src/5-async-work/async_pi_estimate/nan/async.cc

new file mode 100755@@ -0,0 +1,51 @@+#include "async.h"  // NOLINT(build/include)+#include <nan.h>+#include "pi_est.h"  // NOLINT(build/include)++using Nan::AsyncQueueWorker;+using Nan::AsyncWorker;+using Nan::Callback;+using Nan::HandleScope;+using Nan::New;+using Nan::Null;+using Nan::To;+using v8::Function;+using v8::Local;+using v8::Number;+using v8::Value;++class PiWorker : public AsyncWorker {+ public:+  PiWorker(Callback* callback, int points)+      : AsyncWorker(callback), points(points), estimate(0) {}+  ~PiWorker() {}++  // Executed inside the worker-thread.+  // It is not safe to access V8, or V8 data structures+  // here, so everything we need for input and output+  // should go on `this`.+  void Execute() { estimate = Estimate(points); }++  // Executed when the async work is complete+  // this function will be run inside the main event loop+  // so it is safe to use V8 again+  void HandleOKCallback() {+    HandleScope scope;++    Local<Value> argv[] = {Null(), New<Number>(estimate)};++    callback->Call(2, argv, async_resource);+  }++ private:+  int points;+  double estimate;+};++// Asynchronous access to the `Estimate()` function+NAN_METHOD(CalculateAsync) {+  int points = To<int>(info[0]).FromJust();+  Callback* callback = new Callback(To<Function>(info[1]).ToLocalChecked());++  AsyncQueueWorker(new PiWorker(callback, points));+}