Created
October 9, 2024 15:06
-
-
Save robertmryan/0cb300bdbcd560cfa999b817e8f71999 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func upload(files: [URL]) async throws -> Bool { | |
try await withThrowingTaskGroup(of: Bool.self) { group in | |
let session = try SSH(host: "xxx", port:"xxx") | |
let sftp = try session.openSftp() | |
for file in files { | |
group.addTask { | |
try await self.upload(file: file, with: sftp, session: session) | |
} | |
} | |
var count = 0 | |
for try await isSuccessful in group where isSuccessful { | |
count += 1 | |
} | |
return count == files.count | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@williamhqs – Now, regarding your remaining error, that would appear to stem from Shout’s failure to define
SSH
orSFTP
asSendable
. I can’t comment directly on that (as this is not a library that I’ve ever used), but given that it’s using a non-isolatedclass
(rather than an isolated one or anactor
), so that’s not promising. You might want to post an issue there. I confess that I don’t even know if it supports concurrent requests; glancing at the code, I don’t see anyasync
functions, so that is not promising, either.But if you post an issue there, the author might be able to comment further. But prepare yourself for the possibility that simply can’t do that. Or you might have to create a separate session for each upload. I can’t comment without doing a lot more investigation (which I am am afraid that I can’t tackle right now as I’m currently quite busy).