Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Hydra_Internals_11.swift
internal func map_parallel<A, B, S: Sequence>(context: Context, items: S, transform: @escaping (A) throws -> Promise<B>) -> Promise<[B]> where S.Iterator.Element == A {
let transformPromise = Promise<Void>(resolved: ())
return transformPromise.then(in: context) { (Void) -> Promise<[B]> in
do {
let mappedPromises: [Promise<B>] = try items.map({ item in
return try transform(item)
})
return all(mappedPromises)
} catch let error {
return Promise<[B]>(rejected: error)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment