Skip to content

Commit a090ef5

Browse files
author
pioner921227
committed
fixes
1 parent 534969a commit a090ef5

File tree

10 files changed

+1933
-85
lines changed

10 files changed

+1933
-85
lines changed

SyncTasks.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Pod::Spec.new do |s|
1515

1616
s.source_files = "ios/**/*.{h,m,mm}", "cpp/**/*.{hpp,cpp,c,h}"
1717

18+
s.dependency 'curl'
19+
1820
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
1921
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
2022
if respond_to?(:install_modules_dependencies, true)

cpp/TaskScheduler.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ using namespace facebook;
2020
class Task : public jsi::NativeState {
2121
public:
2222
Task(std::string id, int intervalMs, std::function<void(Task&)> job)
23-
: id_(std::move(id)), intervalMs_(intervalMs), job_(std::move(job)) {}
23+
: id_(std::move(id)),job_(std::move(job)), intervalMs_(intervalMs) {}
2424

2525
~Task() = default;
2626

cpp/helpers/fetch.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <curl/curl.h>
1111

12-
1312
using namespace std;
1413

1514
size_t write_callback(void* contents,
@@ -22,43 +21,41 @@ size_t write_callback(void* contents,
2221

2322
struct FetchResult {
2423
std::string body;
25-
26-
FetchResult(std::string b):body(std::move(b)){
27-
}
28-
24+
FetchResult() = default;
25+
FetchResult(std::string b) : body(std::move(b)) {}
2926
};
3027

3128
struct FetchError {
3229
std::string message;
3330
std::string body;
3431
long httpCode = 0;
3532

36-
FetchError(std::string msg, std::string b,long code): message(std::move(msg)), body(std::move(b)), httpCode(code)
37-
{
38-
}
39-
};
40-
33+
FetchError() = default;
4134

35+
FetchError(std::string msg, std::string b, long code)
36+
: message(std::move(msg)), body(std::move(b)), httpCode(code) {}
37+
};
4238

43-
inline std::variant<FetchResult,FetchError> fetch(const char* url, std::unordered_map<std::string,std::string>&& headers) {
39+
inline std::variant<FetchResult, FetchError> fetch(
40+
const char* url,
41+
std::unordered_map<std::string, std::string>&& headers) {
4442
curl_global_init(CURL_GLOBAL_DEFAULT);
4543
CURL* curl = curl_easy_init();
4644

47-
auto result = std::variant<FetchResult,FetchError>();
45+
auto result = std::variant<FetchResult, FetchError>();
4846

4947
std::string response;
5048

5149
if (curl) {
52-
curl_easy_setopt(curl, CURLOPT_URL,
53-
url);
50+
curl_easy_setopt(curl, CURLOPT_URL, url);
5451
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
5552
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
5653

57-
if(headers.size()){
54+
if (headers.size()) {
5855
struct curl_slist* curl_headers = nullptr;
5956

60-
for(auto& it: headers){
61-
std::string h = it.first + ":" + it.second;
57+
for (auto& it : headers) {
58+
std::string h = it.first + ":" + it.second;
6259
curl_headers = curl_slist_append(curl_headers, h.c_str());
6360
}
6461

@@ -70,11 +67,10 @@ inline std::variant<FetchResult,FetchError> fetch(const char* url, std::unordere
7067
long httpCode = 0;
7168
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
7269

73-
7470
if (res == CURLE_OK && httpCode == 200) {
7571
result = FetchResult(response);
7672
} else {
77-
result = FetchError(curl_easy_strerror(res),response,httpCode);
73+
result = FetchError(curl_easy_strerror(res), response, httpCode);
7874
}
7975

8076
curl_easy_cleanup(curl);

cpp/react-native-sync-tasks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ void synctasks::install(jsi::Runtime* rt,
1414
jsi::Runtime& runtime = *rt;
1515

1616
jsi::Object jsTaskManager = createJSTaskManager(runtime);
17-
//
17+
1818
jsi::Function taskCreator = createJSTaskCreator(runtime, callInvoker);
19-
//
19+
2020
runtime.global().setProperty(runtime, SYNC_TASK_MANAGER_KEY,
2121
std::move(jsTaskManager));
22-
//
22+
2323
runtime.global().setProperty(runtime, CREATE_TASK_KEY,
2424
std::move(taskCreator));
2525
}

0 commit comments

Comments
 (0)