 }
 
 // MARK: - Promise
-
 extension Future {
 
     /// A promise to provide a result later.


        /// Sends a result to the associated future.
        public func resolve(result: Result) {
            lock.lock()
            guard self.memoizedResult == nil else {
                lock.unlock(); return // Already resolved
            }
            self.memoizedResult = result
            let inlinedHandler = self.inlinedHandler
            let handlers = self.handlers
            self.inlinedHandler = nil
            self.handlers = nil
            lock.unlock()

            inlinedHandler?(result)
            handlers?.forEach { $0(result) }
        }

        func observe(completion: @escaping (Result) -> Void) {
            lock.lock()
            guard let result = self.memoizedResult else {
                if inlinedHandler == nil {
                    inlinedHandler = completion
                } else {

        private var memoizedResult: Result? // nil when pending
        private var inlinedHandler: ((Result) -> Void)?
        private var handlers: [(Result) -> Void]?
        /// The Lock fastest option (https://gist.github.com/steipete/36350a8a60693d440954b95ea6cbbafc)
        private var lock = os_unfair_lock()

        /// Creates a new pending promise.
        public init() {}
