Skip to content

Commit

Permalink
Improvements to share and refCount.
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Aug 2, 2020
1 parent 657faa9 commit ce0e189
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ReactiveKit.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = "ReactiveKit"
s.version = "3.17.3"
s.version = "3.17.4"
s.summary = "A Swift Reactive Programming Framework"
s.description = "ReactiveKit is a Swift framework for reactive and functional reactive programming."
s.homepage = "https://github.com/DeclarativeHub/ReactiveKit"
s.license = 'MIT'
s.author = { "Srdan Rasic" => "[email protected]" }
s.source = { :git => "https://github.com/DeclarativeHub/ReactiveKit.git", :tag => "v3.17.3" }
s.source = { :git => "https://github.com/DeclarativeHub/ReactiveKit.git", :tag => "v3.17.4" }

s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.11'
Expand Down
6 changes: 2 additions & 4 deletions ReactiveKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 3.17.1;
MARKETING_VERSION = 3.17.4;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -1144,7 +1144,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MACOSX_DEPLOYMENT_TARGET = 10.10;
MARKETING_VERSION = 3.17.1;
MARKETING_VERSION = 3.17.4;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 4.0;
Expand All @@ -1169,7 +1169,6 @@
INFOPLIST_FILE = "Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 3.17.3;
PRODUCT_BUNDLE_IDENTIFIER = DeclarativeHub.ReactiveKit;
PRODUCT_NAME = ReactiveKit;
SKIP_INSTALL = YES;
Expand All @@ -1192,7 +1191,6 @@
INFOPLIST_FILE = "Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
MARKETING_VERSION = 3.17.3;
PRODUCT_BUNDLE_IDENTIFIER = DeclarativeHub.ReactiveKit;
PRODUCT_NAME = ReactiveKit;
SKIP_INSTALL = YES;
Expand Down
11 changes: 7 additions & 4 deletions Sources/Connectable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ extension ConnectableSignalProtocol {

/// Convert connectable signal into the ordinary signal by calling `connect`
/// on the first observation and calling dispose when number of observers goes down to zero.
public func refCount() -> Signal<Element, Error> {
/// - parameter disconnectCount: Subscriptions count on which to disconnect. Defaults to `0`.
public func refCount(disconnectCount: Int = 0) -> Signal<Element, Error> {
let lock = NSRecursiveLock(name: "com.reactive_kit.connectable_signal.ref_count")
var _count = 0
var _connectionDisposable: Disposable? = nil
Expand All @@ -77,7 +78,7 @@ extension ConnectableSignalProtocol {
lock.lock(); defer { lock.unlock() }
disposable.dispose()
_count = _count - 1
if _count == 0 {
if _count == disconnectCount {
_connectionDisposable?.dispose()
_connectionDisposable = nil
}
Expand Down Expand Up @@ -114,8 +115,10 @@ extension SignalProtocol {

/// Ensure that all observers see the same sequence of elements.
/// Shorthand for `replay(limit).refCount()`.
public func share(limit: Int = Int.max) -> Signal<Element, Error> {
return replay(limit: limit).refCount()
/// - parameter limit: Number of latest elements to buffer.
/// - parameter keepAlive: Whether to keep the source signal connected even when all subscribers disconnect.
public func share(limit: Int = Int.max, keepAlive: Bool = false) -> Signal<Element, Error> {
return replay(limit: limit).refCount(disconnectCount: keepAlive ? Int.min : 0)
}
}

Expand Down

0 comments on commit ce0e189

Please sign in to comment.