craft icon indicating copy to clipboard operation
craft copied to clipboard

how to chaining multiple async ?

Open steve21124 opened this issue 9 years ago • 4 comments

in the sample, i see you have 1 chaining for async, how to chain multiple async?

steve21124 avatar Nov 09 '15 03:11 steve21124

So you mean this? https://github.com/supertommy/craft/blob/master/craftTests/craftTests.swift#L171

supertommy avatar Nov 15 '15 04:11 supertommy

Mean't Do* :) typing on an iPad Pro....

supertommy avatar Nov 15 '15 04:11 supertommy

Sorry, I forgot to put more detail on it.

check the section resolve(value: true) and reject(value: false) after then....

how to use "resolve(value: true) and reject(value: false)" for the next then.... then....

func chainingMultipleAsync(completionHandler: ((isValid:Bool) -> Void)){
    //chaining several alerts into one
    let promise = Craft.promise({
        (resolve: (value: Value) -> (), reject: (value: Value) -> ()) -> () in
        
                AlertMessage("Warning!", defaultButton: "OK", alternateButton: "Cancel", otherButton: nil, docWindow: self.view.window!, completionHandler: { (returnInput) -> () in
                    if returnInput == NSAlertFirstButtonReturn
                    {
                        resolve(value: true)
                    }else{
                        reject(value: false)
                    }
                    
                    }, contextInfo: nil, msgFormat: "The first one")
           
    }).then({ (value) -> Value in
        
                AlertMessage("Warning!", defaultButton: "OK", alternateButton: "Cancel", otherButton: nil, docWindow: self.view.window!, completionHandler: { (returnInput) -> () in
                    if returnInput == NSAlertFirstButtonReturn
                    {
                        //NOTE: This need to go to resolve section of the next one
                        resolve(value: true)
                    }else{
                        //NOTE: This need to go to reject section of the next one
                        reject(value: false)
                    }
        
                    }, contextInfo: nil, msgFormat: "The second one")
        
        }) { (value) -> Value in
            
            completionHandler(isValid: false)
        }
    .then({ (value) -> Value in
           completionHandler(isValid: false)
        }) { (value) -> Value in
            completionHandler(isValid: false)
    }
    
}

steve21124 avatar Nov 15 '15 05:11 steve21124

any update on this? thanks

steve21124 avatar Nov 19 '15 19:11 steve21124