react-native-nitro-modules 0.16.2 → 0.18.0

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.
@@ -1,54 +0,0 @@
1
- //
2
- // JSPromise.hpp
3
- // react-native-filament
4
- //
5
- // Created by Marc Rousavy on 11.03.24.
6
- //
7
-
8
- #pragma once
9
-
10
- #include "OwningReference.hpp"
11
- #include <functional>
12
- #include <jsi/jsi.h>
13
- #include <memory>
14
-
15
- namespace margelo::nitro {
16
-
17
- using namespace facebook;
18
-
19
- /**
20
- * Represents a JS Promise.
21
- *
22
- * `JSPromise` is not thread-safe: It has to be resolved/rejected
23
- * on the same thread and Runtime as it was created on.
24
- */
25
- class JSPromise final {
26
- public:
27
- JSPromise(jsi::Runtime& runtime, jsi::Function&& resolver, jsi::Function&& rejecter);
28
-
29
- /**
30
- Resolve the Promise with the given `jsi::Value`.
31
- If the `jsi::Runtime` has already been deleted, this will do nothing.
32
- */
33
- void resolve(jsi::Runtime& runtime, jsi::Value&& result);
34
- /**
35
- Resolve the Promise with the given error message.
36
- If the `jsi::Runtime` has already been deleted, this will do nothing.
37
- */
38
- void reject(jsi::Runtime& runtime, std::string error);
39
-
40
- private:
41
- OwningReference<jsi::Function> _resolver;
42
- OwningReference<jsi::Function> _rejecter;
43
- static constexpr auto TAG = "Promise";
44
-
45
- public:
46
- using RunPromise = std::function<void(jsi::Runtime& runtime, std::shared_ptr<JSPromise> promise)>;
47
- /**
48
- * Create a new Promise using the JS `Promise` constructor and runs the given `run` function.
49
- * The resulting Promise should be returned to JS so it can be awaited.
50
- */
51
- static jsi::Value createPromise(jsi::Runtime& runtime, RunPromise&& run);
52
- };
53
-
54
- } // namespace margelo::nitro
@@ -1,86 +0,0 @@
1
- //
2
- // PromiseHolder.hpp
3
- // Nitro
4
- //
5
- // Created by Marc Rousavy on 15.08.24.
6
- //
7
-
8
- #pragma once
9
-
10
- #include <future>
11
- #include <string>
12
-
13
- namespace margelo::nitro {
14
-
15
- /**
16
- * Holds a `std::promise` that can be accessed from Swift using proper ref management.
17
- */
18
- template <typename T>
19
- class PromiseHolder {
20
- public:
21
- /**
22
- * Create a new PromiseHolder (and a new `std::promise<T>`).
23
- */
24
- explicit PromiseHolder() {
25
- _promise = std::make_shared<std::promise<T>>();
26
- }
27
-
28
- /**
29
- * Resolve the underlying `std::promise<T>` with `T`.
30
- */
31
- void resolve(const T& result) const {
32
- _promise->set_value(result);
33
- }
34
-
35
- /**
36
- * Reject the underlying `std::promise<T>` with the given message.
37
- */
38
- void reject(const std::string& message) const {
39
- try {
40
- throw std::runtime_error(message);
41
- } catch (...) {
42
- _promise->set_exception(std::current_exception());
43
- }
44
- }
45
-
46
- /**
47
- * Get the `std::future<T>` of the underlying `std::promise<T>`.
48
- * This can only be called once.
49
- */
50
- std::future<T> getFuture() {
51
- return _promise->get_future();
52
- }
53
-
54
- private:
55
- std::shared_ptr<std::promise<T>> _promise;
56
- };
57
-
58
- // Specialization for `void` (no args to `resolve()`)
59
- template <>
60
- class PromiseHolder<void> {
61
- public:
62
- explicit PromiseHolder() {
63
- _promise = std::make_shared<std::promise<void>>();
64
- }
65
-
66
- void resolve() const {
67
- _promise->set_value();
68
- }
69
-
70
- void reject(const std::string& message) const {
71
- try {
72
- throw std::runtime_error(message);
73
- } catch (...) {
74
- _promise->set_exception(std::current_exception());
75
- }
76
- }
77
-
78
- std::future<void> getFuture() {
79
- return _promise->get_future();
80
- }
81
-
82
- private:
83
- std::shared_ptr<std::promise<void>> _promise;
84
- };
85
-
86
- } // namespace margelo::nitro