Commit 5b72ecd6 authored by Ignacio Corderi's avatar Ignacio Corderi
Browse files

Added promise() to KineticSession

parent 629a5c87
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
		382D1C00FC0EC4F1BF676411 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; };
		3E07EA7E1B78E3B500DAB3F1 /* Kinetic.proto.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Kinetic.proto.swift; sourceTree = "<group>"; };
		3ED681EA1B7CEA0600AFDF79 /* Encoding.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Encoding.swift; sourceTree = "<group>"; };
		3ED681EE1B7D0EC600AFDF79 /* Example 2 - Async.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = "Example 2 - Async.playground"; sourceTree = "<group>"; };
		3EDAAB3D1B66D32D00F30808 /* Kinetic.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Kinetic.framework; sourceTree = BUILT_PRODUCTS_DIR; };
		3EDAAB401B66D32D00F30808 /* Kinetic.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Kinetic.h; sourceTree = "<group>"; };
		3EDAAB421B66D32D00F30808 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -143,6 +144,7 @@
			isa = PBXGroup;
			children = (
				3EF4F82D1B7BE11400E4EB73 /* Example 1 - Hello World.playground */,
				3ED681EE1B7D0EC600AFDF79 /* Example 2 - Async.playground */,
			);
			path = examples;
			sourceTree = "<group>";
+4 −0
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ public enum KineticConnectionErrors: ErrorType {
    case InvalidMagicNumber
}

public enum PromiseErrors: ErrorType {
    case SomeError(ErrorType)
}

public enum StatusCode : Int {
    case InvalidStatusCode = -1
    case NotAttempted = 0
+17 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@

// @author: Ignacio Corderi

import BrightFutures

/// Contains information about a kinetic device
public struct KineticDevice : Equatable {
    internal let handshake: Command
@@ -73,6 +75,20 @@ public class KineticSession {
            self.credentials = credentials
    }
    
    public func promise<C: ChannelCommand>(cmd: C) -> Future<C.ResponseType, PromiseErrors> {
        let promise = Promise<C.ResponseType, PromiseErrors>()
        
        Queue.global.async {
            do {
                try promise.success(self.send(cmd))
            } catch let err {
                promise.tryFailure(.SomeError(err))
            }
        }
        
        return promise.future
    }
    
    /// Sends a command to the target device and waits for a response
    ///
    /// The type of the result is determined by the command being sent.
+2 −1
Original line number Diff line number Diff line
@@ -4,3 +4,4 @@ use_frameworks!

pod 'ProtocolBuffers-Swift'
pod 'CryptoSwift', :git => "https://github.com/krzyzanowskim/CryptoSwift", :branch => "swift20"
pod 'BrightFutures', :git => "https://github.com/Thomvis/BrightFutures"
 No newline at end of file
+11 −0
Original line number Diff line number Diff line
PODS:
  - BrightFutures (3.0.0-beta.2):
    - Result (= 0.6-beta.1)
  - CryptoSwift (0.0.12)
  - ProtocolBuffers-Swift (2.0)
  - Result (0.6-beta.1)

DEPENDENCIES:
  - BrightFutures (from `https://github.com/Thomvis/BrightFutures`)
  - CryptoSwift (from `https://github.com/krzyzanowskim/CryptoSwift`, branch `swift20`)
  - ProtocolBuffers-Swift

EXTERNAL SOURCES:
  BrightFutures:
    :git: https://github.com/Thomvis/BrightFutures
  CryptoSwift:
    :branch: swift20
    :git: https://github.com/krzyzanowskim/CryptoSwift

CHECKOUT OPTIONS:
  BrightFutures:
    :commit: d12ca54ef5f353fb1bec2517e8b0bd547ec81a5d
    :git: https://github.com/Thomvis/BrightFutures
  CryptoSwift:
    :commit: ad4db3095a9ccc034c1eb65934a89c670012e6a0
    :git: https://github.com/krzyzanowskim/CryptoSwift

SPEC CHECKSUMS:
  BrightFutures: 1f99ca607fd2880a606257c57eb3ebd45299443d
  CryptoSwift: 16f1b5a768057636275b76d1c43231c2abba9e80
  ProtocolBuffers-Swift: cf3b2c2ee00cd89374612d58d6043f409a798b3f
  Result: 6c990ec4a72470672f9fc5b6fef009da0f6f40d1

COCOAPODS: 0.38.2
Loading