You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

26 lines
577 B

//
// Async.swift
// then
//
// Created by Sacha Durand Saint Omer on 13/03/2017.
// Copyright © 2017 s4cha. All rights reserved.
//
import Foundation
import Dispatch
@discardableResult
public func async<T>(block:@escaping () throws -> T) -> Async<T> {
let p = Promise<T> { resolve, reject in
DispatchQueue(label: "then.async.queue", attributes: .concurrent).async {
do {
let t = try block()
resolve(t)
} catch {
reject(error)
}
}
}
p.start()
return p
}