Skip to content

Commit

Permalink
Some working async
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdy committed May 9, 2024
1 parent 8f6786c commit d3c9feb
Show file tree
Hide file tree
Showing 16 changed files with 2,531 additions and 1,638 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,19 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.cc]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.h]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
"preinstall": "scripts/download-libraries.sh",
"load": "node --max-old-space-size=500 scripts/dumpster-fire.js",
"install": "scripts/build.sh",
"test:mocha-debug": "lldb -o run -- node node_modules/mocha/bin/mocha --inspect-brk",
"test:mocha": "mocha",
"test": "nyc npm run test:mocha",
"debug": "nyc npm run test:mocha-debug",
"posttest": "npm run lint",
"lint": "eslint src/ --ext .ts --fix"
},
Expand Down
1,451 changes: 935 additions & 516 deletions src/asherah.cc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/asherah.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,4 @@ export declare function encrypt_string_async(partitionId: string, data: string):
export declare function set_max_stack_alloc_item_size(max_item_size: number): void;
export declare function set_safety_padding_overhead(safety_padding_overhead: number): void;
export declare function set_log_hook(logHook: LogHookCallback): void;
export declare function get_setup_status(): boolean;
36 changes: 0 additions & 36 deletions src/asherah_async_worker.cc

This file was deleted.

65 changes: 35 additions & 30 deletions src/asherah_async_worker.h
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 &param1);
~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 &param1, const Napi::Value &param2);
~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
2 changes: 0 additions & 2 deletions src/cobhan.cc

This file was deleted.

133 changes: 0 additions & 133 deletions src/cobhan.h

This file was deleted.

Loading

0 comments on commit d3c9feb

Please sign in to comment.