Skip to content

Commit

Permalink
Fixed location for Promise+Observer
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele committed Jun 9, 2017
1 parent 0e104f8 commit fed7ff6
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Hydra/Hydra.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
08E253C91E4201FA00432D2C /* Promise+Timeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08E253B81E4201FA00432D2C /* Promise+Timeout.swift */; };
08E253CA1E4201FA00432D2C /* Promise+Validate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08E253B91E4201FA00432D2C /* Promise+Validate.swift */; };
08E253CB1E4201FA00432D2C /* Promise+Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08E253BA1E4201FA00432D2C /* Promise+Zip.swift */; };
64A0E9971EEAC79B00E57CC4 /* Promise+Observer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64A0E9961EEAC79B00E57CC4 /* Promise+Observer.swift */; };
C227188D1EDCFE3200AB10CF /* Promise+State.swift in Sources */ = {isa = PBXBuildFile; fileRef = C227188C1EDCFE3200AB10CF /* Promise+State.swift */; };
C227188F1EDCFE6900AB10CF /* Promise+Observer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C227188E1EDCFE6900AB10CF /* Promise+Observer.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -89,8 +89,8 @@
08E253B81E4201FA00432D2C /* Promise+Timeout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Promise+Timeout.swift"; path = "../Sources/Hydra/Promise+Timeout.swift"; sourceTree = "<group>"; };
08E253B91E4201FA00432D2C /* Promise+Validate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Promise+Validate.swift"; path = "../Sources/Hydra/Promise+Validate.swift"; sourceTree = "<group>"; };
08E253BA1E4201FA00432D2C /* Promise+Zip.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Promise+Zip.swift"; path = "../Sources/Hydra/Promise+Zip.swift"; sourceTree = "<group>"; };
64A0E9961EEAC79B00E57CC4 /* Promise+Observer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Promise+Observer.swift"; path = "../Sources/Hydra/Promise+Observer.swift"; sourceTree = "<group>"; };
C227188C1EDCFE3200AB10CF /* Promise+State.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Promise+State.swift"; path = "../Sources/Hydra/Promise+State.swift"; sourceTree = "<group>"; };
C227188E1EDCFE6900AB10CF /* Promise+Observer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Promise+Observer.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -178,9 +178,9 @@
children = (
08E253AD1E4201FA00432D2C /* Promise.swift */,
C227188C1EDCFE3200AB10CF /* Promise+State.swift */,
C227188E1EDCFE6900AB10CF /* Promise+Observer.swift */,
08E253AB1E4201FA00432D2C /* Commons.swift */,
08E253AC1E4201FA00432D2C /* Context.swift */,
64A0E9961EEAC79B00E57CC4 /* Promise+Observer.swift */,
08E253CC1E4205CD00432D2C /* Operators */,
);
name = Sources;
Expand Down Expand Up @@ -378,7 +378,7 @@
08E253BB1E4201FA00432D2C /* Promise+Await.swift in Sources */,
08E253BE1E4201FA00432D2C /* Promise.swift in Sources */,
08E253C31E4201FA00432D2C /* Promise+Defer.swift in Sources */,
C227188F1EDCFE6900AB10CF /* Promise+Observer.swift in Sources */,
64A0E9971EEAC79B00E57CC4 /* Promise+Observer.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CI Status](https://travis-ci.org/malcommac/HydraAsync.svg)](https://travis-ci.org/malcommac/HydraAsync) [![Version](https://img.shields.io/cocoapods/v/HydraAsync.svg?style=flat)](http://cocoadocs.org/docsets/HydraAsync) [![License](https://img.shields.io/cocoapods/l/HydraAsync.svg?style=flat)](http://cocoadocs.org/docsets/HydraAsync) [![Platform](https://img.shields.io/cocoapods/p/HydraAsync.svg?style=flat)](http://cocoadocs.org/docsets/HydraAsync)

<p align="center" >Love your async code again with Hydra <br/>
Made with ♥ in pure Swift 3+, no dependencies, lightweight & fully portable
Made with ♥ in pure Swift (both 3.x and 4.x), no dependencies, lightweight & fully portable
<p/>
<p align="center" >★★ <b>Star our github repository to help us!</b> ★★</p>
<p align="center" >Created by <a href="http://www.danielemargutti.com">Daniele Margutti</a> (<a href="http://www.twitter.com/danielemargutti">@danielemargutti</a>)</p>
Expand Down
71 changes: 71 additions & 0 deletions Sources/Hydra/Promise+Observer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Hydra
* Fullfeatured lightweight Promise & Await Library for Swift
*
* Created by: Daniele Margutti
* Email: [email protected]
* Web: http://www.danielemargutti.com
* Twitter: @danielemargutti
*
* Copyright © 2017 Daniele Margutti
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/


import Foundation

extension Promise {

//MARK: Promise Observer

/// This enum represent an observer which receive the state of a promise.
///
/// - onResolve: register an handler which is executed only if target promise is fulfilled.
/// - onReject: register an handler which is executed only if target promise is rejected.
internal indirect enum Observer {
typealias ResolveObserver = ((Value) -> (Void))
typealias RejectObserver = ((Error) -> (Void))

case onResolve(_: Context, _: ResolveObserver)
case onReject(_: Context, _: RejectObserver)

/// Call the observer by state
///
/// - Parameter state: State
func call(_ state: State) {
switch (self, state) {
case (.onResolve(let context, let handler), .resolved(let value)):
context.queue.async {
handler(value)
}
case (.onReject(let context, let handler), .rejected(let error)):
context.queue.async {
handler(error)
}
default:
return
}
}

}

}

0 comments on commit fed7ff6

Please sign in to comment.