2015-04-08 01:28:38 +03:00
|
|
|
//
|
|
|
|
// Subscription.swift
|
2016-10-15 15:38:22 +03:00
|
|
|
// RxTest
|
2015-04-08 01:28:38 +03:00
|
|
|
//
|
|
|
|
// Created by Krunoslav Zaher on 2/14/15.
|
2015-12-29 18:56:21 +03:00
|
|
|
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
2015-04-08 01:28:38 +03:00
|
|
|
//
|
|
|
|
|
2016-10-23 20:26:22 +03:00
|
|
|
/// Records information about subscriptions to and unsubscriptions from observable sequences.
|
2015-12-20 02:44:51 +03:00
|
|
|
public struct Subscription
|
2016-10-23 20:26:22 +03:00
|
|
|
{
|
2015-11-09 03:05:51 +03:00
|
|
|
|
2016-10-23 20:26:22 +03:00
|
|
|
/// Subscription virtual time.
|
2015-12-20 02:44:51 +03:00
|
|
|
public let subscribe : Int
|
2016-10-23 20:26:22 +03:00
|
|
|
/// Unsubscription virtual time.
|
2015-12-20 02:44:51 +03:00
|
|
|
public let unsubscribe : Int
|
2015-12-20 17:34:26 +03:00
|
|
|
|
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.
|
2015-12-20 02:44:51 +03:00
|
|
|
public init(_ subscribe: Int) {
|
2015-04-08 01:28:38 +03:00
|
|
|
self.subscribe = subscribe
|
|
|
|
self.unsubscribe = Int.max
|
|
|
|
}
|
2015-12-20 17:34:26 +03:00
|
|
|
|
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.
|
2015-12-20 02:44:51 +03:00
|
|
|
public init(_ subscribe: Int, _ unsubscribe: Int) {
|
2015-04-08 01:28:38 +03:00
|
|
|
self.subscribe = subscribe
|
|
|
|
self.unsubscribe = unsubscribe
|
|
|
|
}
|
2016-10-23 20:26:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Subscription
|
|
|
|
: Hashable
|
|
|
|
, Equatable {
|
|
|
|
/// The hash value.
|
2015-12-20 02:44:51 +03:00
|
|
|
public var hashValue : Int {
|
2016-03-07 20:31:00 +03:00
|
|
|
return subscribe.hashValue ^ unsubscribe.hashValue
|
2015-04-08 01:28:38 +03:00
|
|
|
}
|
2015-11-09 03:05:51 +03:00
|
|
|
}
|
|
|
|
|
2016-10-23 20:26:22 +03:00
|
|
|
extension Subscription
|
|
|
|
: CustomDebugStringConvertible {
|
|
|
|
/// A textual representation of `self`, suitable for debugging.
|
2015-12-20 02:44:51 +03:00
|
|
|
public var debugDescription : String {
|
2016-03-07 20:31:00 +03:00
|
|
|
let infiniteText = "Infinity"
|
|
|
|
return "(\(subscribe) : \(unsubscribe != Int.max ? String(unsubscribe) : infiniteText))"
|
2015-04-08 01:28:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-20 02:44:51 +03:00
|
|
|
public func == (lhs: Subscription, rhs: Subscription) -> Bool {
|
2015-04-08 01:28:38 +03:00
|
|
|
return lhs.subscribe == rhs.subscribe && lhs.unsubscribe == rhs.unsubscribe
|
2016-10-15 15:38:22 +03:00
|
|
|
}
|