This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
141 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
Foundation/AuxiliaryExecute/Sources/AuxiliaryExecute/AuxiliaryExecute+Async.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// | ||
// AuxiliaryExecute+Spawn.swift | ||
// AuxiliaryExecute | ||
// | ||
// Created by Cyandev on 2022/1/10. | ||
// | ||
|
||
#if swift(>=5.5) | ||
|
||
import Foundation | ||
|
||
@available(iOS 15.0, macOS 12.0.0, *) | ||
public extension AuxiliaryExecute { | ||
/// async/await function for spawn using withCheckedContinuation | ||
/// - Parameters: | ||
/// - command: full path of the binary file. eg: "/bin/cat" | ||
/// - args: arg to pass to the binary, exclude argv[0] which is the path itself. eg: ["nya"] | ||
/// - environment: any environment to be appended/overwrite when calling posix spawn. eg: ["mua" : "nya"] | ||
/// - timeout: any wall timeout if lager than 0, in seconds. eg: 6 | ||
/// - stdout: a block call from pipeControlQueue in background when buffer from stdout available for read | ||
/// - stderr: a block call from pipeControlQueue in background when buffer from stderr available for read | ||
/// - Returns: execution recipe, see it's definition for details | ||
@discardableResult | ||
static func spawnAsync( | ||
command: String, | ||
args: [String] = [], | ||
environment: [String: String] = [:], | ||
timeout: Double = 0, | ||
stdoutBlock: ((String) -> Void)? = nil, | ||
stderrBlock: ((String) -> Void)? = nil | ||
) async -> ExecuteRecipe { | ||
await withCheckedContinuation { cont in | ||
self.spawn( | ||
command: command, | ||
args: args, | ||
environment: environment, | ||
timeout: timeout, | ||
stdoutBlock: stdoutBlock, | ||
stderrBlock: stderrBlock | ||
) { recipe in | ||
cont.resume(returning: recipe) | ||
} | ||
} | ||
} | ||
|
||
/// async/await function for spawn using withCheckedContinuation | ||
/// - Parameters: | ||
/// - command: full path of the binary file. eg: "/bin/cat" | ||
/// - args: arg to pass to the binary, exclude argv[0] which is the path itself. eg: ["nya"] | ||
/// - environment: any environment to be appended/overwrite when calling posix spawn. eg: ["mua" : "nya"] | ||
/// - timeout: any wall timeout if lager than 0, in seconds. eg: 6 | ||
/// - output: a block call from pipeControlQueue in background when buffer from stdout or stderr available for read | ||
/// - Returns: execution recipe, see it's definition for details | ||
@discardableResult | ||
static func spawnAsync( | ||
command: String, | ||
args: [String] = [], | ||
environment: [String: String] = [:], | ||
timeout: Double = 0, | ||
output: ((String) -> Void)? = nil | ||
) async -> ExecuteRecipe { | ||
let lock = NSLock() | ||
return await spawnAsync( | ||
command: command, | ||
args: args, | ||
environment: environment, | ||
timeout: timeout, | ||
stdoutBlock: { str in | ||
lock.lock() | ||
output?(str) | ||
lock.unlock() | ||
}, stderrBlock: { str in | ||
lock.lock() | ||
output?(str) | ||
lock.unlock() | ||
} | ||
) | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ Author: Lakr Aream <[email protected]> | |
Maintainer: Lakr Aream <[email protected]> | ||
Version: @@VERSION@@ | ||
Section: Applications | ||
Pre-Depends: firmware (>= 13.0) | ||
Pre-Depends: firmware (>= 13.5) | ||
Architecture: iphoneos-arm | ||
depiction: https://moreinfo.thebigboss.org/moreinfo/depiction.php?file=iridiumDp | ||
tag: purpose::uikit |