1728528263
Anonymous
Я столкнулся с этой ошибкой в Swift 6, все сообщение:
Task-isolated value of type '() async throws -> Bool' passed as a strongly transferred parameter; later accesses could race; this is an error in the Swift 6 language mode
[img]https://i.sstatic.net/xV2Gxfei.png[/img]
вот код:
actor SftpUploader {
func upload(files: [URL]) async throws -> Bool {
let session = try SSH(host: "xxx", port:"xxx")
let sftp = try session.openSftp()
let results = try await withThrowingTaskGroup(of: Bool.self, returning: [Bool].self) { [weak self] group in
guard let self = self else { return [] }
for file in files {
group.addTask { Bool {
//logic code
}
}
Не совсем уверен в ошибке. Такое ощущение, что результат метода upload() был передан в addTask. Спасибо за любую помощь.
[b]EDIT2[/b]
Спасибо за комментарий @Rob. Я переместил параметр session и sftp внутрь блока TaskGroup, ошибка превратилась в:
Value of non-Sendable type '@isolated(any) @async @callee_guaranteed @substituted () -> (@out τ_0_0, @error any Error) for ' accessed after being transferred; later accesses could race; this is an error in the Swift 6 language mode
[img]https://i.sstatic.net/65rVFVPB.png[/img]
Вот код:
import Foundation
@preconcurrency import Shout
actor SftpUploader {
func upload(files: [URL]) async throws -> Bool {
guard self.isGenerateKeysFileSuccess else {
return false
}
let results = try await withThrowingTaskGroup(of: Bool.self, returning: [Bool].self) { [weak self] group in
guard let self = self else { return [] }
let session = try SSH(host: "xxx", port: xxx)
try session.authenticate(xxx)
let sftp = try session.openSftp()
for file in files {
group.addTask {
return try await self.upload(file: file, with: sftp, session: session)
}
}
return try await group.reduce(into: [Bool]()) { partialResult, isSuccess in
partialResult.append(isSuccess)
}
}
return results.count == files.count
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79069719/task-isolated-value-of-type-passed-as-a-strongly-transferred-parameter-later-ac[/url]