-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
2,531 additions
and
1,638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,47 @@ | ||
// | ||
// Created by Jeremiah Gowdy on 5/6/24. | ||
// | ||
// asherah_async_worker.h | ||
#ifndef ASHERAH_ASYNC_WORKER_H | ||
#define ASHERAH_ASYNC_WORKER_H | ||
|
||
#ifndef ASHERAH_NODE_ASHERAH_ASYNC_WORKER_H | ||
#define ASHERAH_NODE_ASHERAH_ASYNC_WORKER_H | ||
#include <napi.h> | ||
class Asherah; | ||
|
||
#include <stdexcept> | ||
|
||
#define ASHERAH_ASYNC_WORKER(CLASS_NAME, RESULT_TYPE) \ | ||
class CLASS_NAME : public AsherahAsyncWorker<RESULT_TYPE> { \ | ||
public: \ | ||
CLASS_NAME(Napi::Function& callback) : AsherahAsyncWorker(callback) {} \ | ||
\ | ||
protected: \ | ||
RESULT_TYPE ExecuteTask() override; \ | ||
} | ||
|
||
template <typename ResultType> | ||
class AsherahAsyncWorker : public Napi::AsyncWorker { | ||
public: | ||
explicit AsherahAsyncWorker(const Napi::Env &env, Asherah *instance); | ||
Napi::Promise Promise(); | ||
protected: | ||
Asherah *asherah; | ||
Napi::Promise::Deferred promise; | ||
Napi::Value result; | ||
AsherahAsyncWorker(Napi::Function& callback) | ||
: Napi::AsyncWorker(callback) {} | ||
|
||
void OnOK() override; | ||
void OnError(const Napi::Error &e) override; | ||
}; | ||
void OnOK() override { | ||
Napi::HandleScope scope(Env()); | ||
Callback().Call({Env().Undefined(), result}); | ||
} | ||
|
||
class AsherahAsyncWorker1 : public AsherahAsyncWorker { | ||
public: | ||
AsherahAsyncWorker1(const Napi::Env &env, Asherah *instance, const Napi::Value ¶m1); | ||
~AsherahAsyncWorker1() override; | ||
void OnError(Napi::Error const &error) override { | ||
Napi::HandleScope scope(Env()); | ||
Callback().Call({error.Value()}); | ||
} | ||
|
||
protected: | ||
Napi::Reference<Napi::Value> param1Ref; | ||
}; | ||
ResultType result; | ||
|
||
class AsherahAsyncWorker2 : public AsherahAsyncWorker { | ||
public: | ||
AsherahAsyncWorker2(const Napi::Env &env, Asherah *instance, const Napi::Value ¶m1, const Napi::Value ¶m2); | ||
~AsherahAsyncWorker2() override; | ||
virtual ResultType ExecuteTask() = 0; | ||
|
||
protected: | ||
Napi::Reference<Napi::Value> param1Ref; | ||
Napi::Reference<Napi::Value> param2Ref; | ||
void Execute() override { | ||
try { | ||
result = ExecuteTask(); | ||
} catch (const std::exception& ex) { | ||
SetError(ex.what()); | ||
} | ||
} | ||
}; | ||
|
||
#endif //ASHERAH_NODE_ASHERAH_ASYNC_WORKER_H | ||
#endif // ASHERAH_ASYNC_WORKER_H |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.