036856aed5
* Move everything into package * Remove .DS_Store * Move scripts and eslintrc to package * Create CODE_OF_CONDUCT.md * fix some links * Update all links (I think) * Update generated docs * Update notice-yarn-changes.yml * Update validate-android.yml * Update validate-cpp.yml * Delete notice-yarn-changes.yml * Update validate-cpp.yml * Update validate-cpp.yml * Update validate-js.yml * Update validate-cpp.yml * Update validate-cpp.yml * wrong c++ style * Revert "wrong c++ style" This reverts commit 55a3575589c6f13f8b05134d83384f55e0601ab2.
50 lines
976 B
Swift
50 lines
976 B
Swift
//
|
|
// Callback.swift
|
|
// VisionCamera
|
|
//
|
|
// Created by Marc Rousavy on 07.06.21.
|
|
// Copyright © 2021 mrousavy. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
/**
|
|
Represents a callback to JavaScript. Syntax is the same as with Promise.
|
|
*/
|
|
class Callback {
|
|
private var hasCalled = false
|
|
private let callback: RCTResponseSenderBlock
|
|
|
|
init(_ callback: @escaping RCTResponseSenderBlock) {
|
|
self.callback = callback
|
|
}
|
|
|
|
func reject(error: CameraError, cause: NSError?) {
|
|
guard !hasCalled else { return }
|
|
|
|
callback([NSNull(), makeReactError(error, cause: cause)])
|
|
hasCalled = true
|
|
}
|
|
|
|
func reject(error: CameraError) {
|
|
guard !hasCalled else { return }
|
|
|
|
reject(error: error, cause: nil)
|
|
hasCalled = true
|
|
}
|
|
|
|
func resolve(_ value: Any) {
|
|
guard !hasCalled else { return }
|
|
|
|
callback([value, NSNull()])
|
|
hasCalled = true
|
|
}
|
|
|
|
func resolve() {
|
|
guard !hasCalled else { return }
|
|
|
|
resolve(NSNull())
|
|
hasCalled = true
|
|
}
|
|
}
|