     }
 
     @discardableResult
-    open func finally(_ context: @escaping ExecutionContext = defaultExecutionContext, handler: @escaping (Void) -> Void) -> Future<T> {
-        self.syncQueue.async {
-            let completionHandler = FutureCompletionHandler<T>.finally(task: handler, context: context)
+    public func finally(on queue: DispatchQueue = DispatchQueue.main,
+                        handler: @escaping (Void) -> Void) -> Future<T> {
+        syncQueue.async {
+            let completionHandler = FutureCompletionHandler<T>.finally(task: handler, queue: queue)
             switch self.state {
             case .pending:
                 self.deferCompletionHandler(completionHandler)

    }
    
    fileprivate func executeDeferedCompletionHandlers() {
        self.stateHandlers.forEach { self.executeCompletionHandler($0) }
        self.stateHandlers = []
    }

    fileprivate func executeCompletionHandler(_ handler: FutureCompletionHandler<T>) {
        switch (handler, self.state) {
        case (.success(let successHandler, let context), .fulfilled(let value)):
            _ = context { successHandler(value) }()
        case (.failure(let failureHandler, let context), .rejected(let error)):
            _ = context { failureHandler(error) }()
        case (.finally(let finalHandler, let context), _) where !self.state.isPending:
            _ = context { finalHandler() }()
        default: break
        }
    }
    
    fileprivate func deferCompletionHandler(_ handler: FutureCompletionHandler<T>) {
        self.stateHandlers.append(handler)
    }
    
    @discardableResult
    open func onSuccess(_ context: @escaping ExecutionContext = defaultExecutionContext, successHandler: @escaping (T) -> Void) -> Future<T> {
        self.syncQueue.async {
            let completionHandler = FutureCompletionHandler.success(task: successHandler, context: context)
            switch self.state {
            case .pending:
                self.deferCompletionHandler(completionHandler)

    }
}

fileprivate enum FutureCompletionHandler<T> {
    case success(task: (T) -> Void, queue: DispatchQueue)
    case failure(task: (Error) -> Void, queue: DispatchQueue)
    case finally(task: (Void) -> Void, queue: DispatchQueue)
}

public enum FutureError : Error {
    case futureStillPending
}

public class Future<T> {

    private let futureIdentifierKey = DispatchSpecificKey<String>()

    fileprivate let syncQueue: DispatchQueue!
    
    internal var state: FutureState<T> = .pending {
        willSet {
            guard case .pending = state else {
                assertionFailure("Future state can not be changed as it is \(state) already")
                return
            }
        }
