Skip to content

Commit

Permalink
Completion handlers should fire anyway.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatey committed Jul 22, 2015
1 parent 0705986 commit b3277bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions Source/Client.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public class Client {

public func fetch(completionHandler: ((error: NSError?) -> Void)? = nil) {
session.lights(selector: "all") { [weak self] (request, response, lights, error) in
if let strongSelf = self {
if error != nil {
completionHandler?(error: error)
return
}
if error != nil {
completionHandler?(error: error)
return
}

if let strongSelf = self {
let oldLights = strongSelf.lights
let newLights = lights
if oldLights != newLights {
Expand All @@ -39,8 +39,9 @@ public class Client {
}
}

completionHandler?(error: nil)
}

completionHandler?(error: nil)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Source/LightTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ public class LightTarget {
newLights = newLights.map({ $0.lightWithPower(oldPower) })
}
strongSelf.client.updateLights(newLights)
completionHandler?(results: results, error: error)
}
completionHandler?(results: results, error: error)
}
}

Expand All @@ -148,8 +148,8 @@ public class LightTarget {
newLights = newLights.map({ $0.lightWithColor(oldColor, andBrightness: oldBrightness) })
}
strongSelf.client.updateLights(newLights)
completionHandler?(results: results, error: error)
}
completionHandler?(results: results, error: error)
}
}

Expand Down

0 comments on commit b3277bf

Please sign in to comment.