Skip to content

Commit

Permalink
more ios
Browse files Browse the repository at this point in the history
  • Loading branch information
Erfan Shekarchi committed Mar 29, 2024
1 parent da41b78 commit 9ced3f5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion ios/Fula.mm
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ @interface RCT_EXTERN_MODULE(FulaModule, NSObject)
withResolver:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(getDatastoreSize:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(getDatastoreSize:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)

+ (BOOL)requiresMainQueueSetup
{
Expand Down
34 changes: 24 additions & 10 deletions ios/Fula.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1514,19 +1514,33 @@ class FulaModule: NSObject {
}
}

@objc(getDatastoreSizeWithResolver:withRejecter:)
func getDatastoreSize(resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
do {
let result = try self.fula!.getDatastoreSize()
let resultString = result.toUTF8String()!
resolve(resultString)
} catch let error {
print("getDatastoreSize", error.localizedDescription)
let nsError = error as NSError
reject("ERR_FULA", "Failed to get datastore size", nsError)
@objc
func getDatastoreSize(_ resolve: @escaping RCTPromiseResolveBlock, rejecter reject: @escaping RCTPromiseRejectBlock) {
DispatchQueue.global(qos: .background).async {
// Safely unwrap `self.fula` using `guard let`
guard let fulaClient = self.fula else {
let error = NSError(domain: "FulaModuleError", code: 0, userInfo: [NSLocalizedDescriptionKey: "Fula client is not initialized"])
DispatchQueue.main.async {
reject("ERR_FULA_NOT_INITIALIZED", "Fula client is not initialized", error)
}
return
}

do {
let result = try fulaClient.getDatastoreSize()
let resultString = String(decoding: result, as: UTF8.self)
DispatchQueue.main.async {
resolve(resultString)
}
} catch let error {
DispatchQueue.main.async {
reject("ERR_FULA", "Failed to get datastore size: \(error.localizedDescription)", error)
}
}
}
}


//Add Replicate In Pool (replicateInPool)

}
Expand Down

0 comments on commit 9ced3f5

Please sign in to comment.