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.
 
 
 
 

28 lines
657 B

//
// Promise+Finally.swift
// then
//
// Created by Sacha Durand Saint Omer on 20/02/2017.
// Copyright © 2017 s4cha. All rights reserved.
//
import Foundation
public extension Promise {
public func finally(_ block: @escaping () -> Void) {
tryStartInitialPromiseAndStartIfneeded()
registerFinally(block)
}
public func registerFinally(_ block: @escaping () -> Void) {
synchronize { state, blocks in
switch state {
case .rejected, .fulfilled:
block()
case .dormant, .pending:
blocks.finally.append(block)
}
}
}
}