import Dispatch /** Judicious use of `firstly` *may* make chains more readable. Compare: URLSession.shared.dataTask(url: url1).then { URLSession.shared.dataTask(url: url2) }.then { URLSession.shared.dataTask(url: url3) } With: firstly { URLSession.shared.dataTask(url: url1) }.then { URLSession.shared.dataTask(url: url2) }.then { URLSession.shared.dataTask(url: url3) } - Note: the block you pass excecutes immediately on the current thread/queue. */ public func firstly(execute body: () throws -> U) -> Promise { do { let rp = Promise(.pending) try body().pipe(to: rp.box.seal) return rp } catch { return Promise(error: error) } } /// - See: firstly() public func firstly(execute body: () -> Guarantee) -> Guarantee { return body() }