func chained()

in Source/AwsCommonRuntimeKit/crt/Future.swift [73:93]


    func chained<T>(closure: @escaping (FutureResult) -> Future<T>) -> Future<T> {
        // We'll start by constructing a "wrapper" promise that will be
        // returned from this method:
        let promise = Future<T>()

        // Observe the current future:
        then { result in
            let future = closure(result)

            future.then { result in
                switch result {
                case .failure(let error):
                    promise.fail(error)
                case .success(let value):
                    promise.fulfill(value)
                }
            }
        }

        return promise
    }