Created
February 4, 2017 11:17
-
-
Save malcommac/f85480fd868b6bb93941b77571898c66 to your computer and use it in GitHub Desktop.
Hydra_Internals_11.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
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