RxSwift/RxTest/Subscription.swift

58 lines
1.7 KiB
Swift
Raw Normal View History

//
// Subscription.swift
2016-10-15 15:38:22 +03:00
// RxTest
//
// Created by Krunoslav Zaher on 2/14/15.
2015-12-29 18:56:21 +03:00
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
2016-10-23 20:26:22 +03:00
/// Records information about subscriptions to and unsubscriptions from observable sequences.
public struct Subscription
2016-10-23 20:26:22 +03:00
{
2016-10-23 20:26:22 +03:00
/// Subscription virtual time.
public let subscribe : Int
2016-10-23 20:26:22 +03:00
/// Unsubscription virtual time.
public let unsubscribe : Int
2016-10-23 20:26:22 +03:00
/// Creates a new subscription object with the given virtual subscription time.
///
/// - parameter subscribe: Virtual time at which the subscription occurred.
public init(_ subscribe: Int) {
self.subscribe = subscribe
self.unsubscribe = Int.max
}
2016-10-23 20:26:22 +03:00
/// Creates a new subscription object with the given virtual subscription and unsubscription time.
///
/// - parameter subscribe: Virtual time at which the subscription occurred.
/// - parameter unsubscribe: Virtual time at which the unsubscription occurred.
public init(_ subscribe: Int, _ unsubscribe: Int) {
self.subscribe = subscribe
self.unsubscribe = unsubscribe
}
2016-10-23 20:26:22 +03:00
}
extension Subscription
: Hashable
, Equatable {
/// The hash value.
public var hashValue : Int {
2016-03-07 20:31:00 +03:00
return subscribe.hashValue ^ unsubscribe.hashValue
}
}
2016-10-23 20:26:22 +03:00
extension Subscription
: CustomDebugStringConvertible {
/// A textual representation of `self`, suitable for debugging.
public var debugDescription : String {
2016-03-07 20:31:00 +03:00
let infiniteText = "Infinity"
return "(\(subscribe) : \(unsubscribe != Int.max ? String(unsubscribe) : infiniteText))"
}
}
public func == (lhs: Subscription, rhs: Subscription) -> Bool {
return lhs.subscribe == rhs.subscribe && lhs.unsubscribe == rhs.unsubscribe
2016-10-15 15:38:22 +03:00
}