DiferredJust for Single

This commit is contained in:
Pavel Lukandiy 2017-09-04 22:20:25 +03:00
parent 73af67cc20
commit e845758204
3 changed files with 57 additions and 2 deletions

View File

@ -383,6 +383,7 @@
67E6C2361EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; };
67E6C2371EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; };
67E6C2381EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; };
82F8BB181F5DDED100C1061B /* Single+DeferredJust.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */; };
BA6C6DB45950382041948FC5 /* Pods_LeadKit_LeadKit_iOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CFE9323150A9760008093F73 /* Pods_LeadKit_LeadKit_iOS.framework */; };
D6EE55093E404DEA62B03DDF /* Pods_LeadKit_LeadKit_watchOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8590CA7831555C295C5DC572 /* Pods_LeadKit_LeadKit_watchOS.framework */; };
DEE25FE98D40ED1C168F384A /* Pods_LeadKit_LeadKit_iOS_Extensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 887F99C5326BD220C2811BD6 /* Pods_LeadKit_LeadKit_iOS_Extensions.framework */; };
@ -563,6 +564,7 @@
67CDEE411EB3AD1C00895905 /* NetworkService+RxLoadImage.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NetworkService+RxLoadImage.swift"; sourceTree = "<group>"; };
67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleLoadCursor.swift; sourceTree = "<group>"; };
78405D3B3D3C3E17456877FF /* Pods_LeadKit_iOSTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_iOSTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Single+DeferredJust.swift"; sourceTree = "<group>"; };
8590CA7831555C295C5DC572 /* Pods_LeadKit_LeadKit_watchOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_LeadKit_watchOS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
887F99C5326BD220C2811BD6 /* Pods_LeadKit_LeadKit_iOS_Extensions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_LeadKit_iOS_Extensions.framework; sourceTree = BUILT_PRODUCTS_DIR; };
95E457F1241D136396FC2420 /* Pods_LeadKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@ -743,6 +745,7 @@
671461F01EB3396E00EAB194 /* Observable */,
671461F31EB3396E00EAB194 /* PaginationTableViewWrapperDelegate */,
671461F51EB3396E00EAB194 /* Sequence */,
82F8BB161F5DDED100C1061B /* Single */,
671461F71EB3396E00EAB194 /* StoryboardProtocol */,
671461FA1EB3396E00EAB194 /* String */,
671461FE1EB3396E00EAB194 /* Support */,
@ -1200,6 +1203,14 @@
name = Products;
sourceTree = "<group>";
};
82F8BB161F5DDED100C1061B /* Single */ = {
isa = PBXGroup;
children = (
82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */,
);
path = Single;
sourceTree = "<group>";
};
C90516DF61394D92FF071C0C /* Frameworks */ = {
isa = PBXGroup;
children = (
@ -1938,6 +1949,7 @@
67051ADB1EBC7C36008EADC0 /* SpinnerView.swift in Sources */,
671463581EB3396E00EAB194 /* StoryboardIdentifierProtocol.swift in Sources */,
67A1FF941EBCA65E00D6C89F /* CABasicAnimation+Rotation.swift in Sources */,
82F8BB181F5DDED100C1061B /* Single+DeferredJust.swift in Sources */,
671463301EB3396E00EAB194 /* CursorType.swift in Sources */,
6714624C1EB3396E00EAB194 /* MapCursor.swift in Sources */,
671463241EB3396E00EAB194 /* Any+TypeName.swift in Sources */,

View File

@ -60,7 +60,7 @@ open class XibView: UIView {
/// Provide initial configuration. Called once
open func configure() {
}
}

View File

@ -0,0 +1,43 @@
//
// Copyright (c) 2017 Touch Instinct
//
// 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 RxSwift
public extension Single {
/// Returns an single that invokes the specified factory function whenever a new observer subscribes.
///
/// - Parameter elementFactory: Element factory function to invoke for each observer
/// that subscribes to the resulting sequence.
/// - Returns: An observable sequence whose observers trigger an invocation of the given element factory function.
static func deferredJust(_ elementFactory: @escaping () throws -> Element) -> Single<Element> {
return .create(subscribe: { (observer) -> Disposable in
do {
observer(.success(try elementFactory()))
} catch {
observer(.error(error))
}
return Disposables.create()
})
}
}