diff --git a/LeadKit/LeadKit/Classes/Cursors/FixedPageCursor.swift b/LeadKit/LeadKit/Classes/Cursors/FixedPageCursor.swift index 19a36b8c..09914bd9 100644 --- a/LeadKit/LeadKit/Classes/Cursors/FixedPageCursor.swift +++ b/LeadKit/LeadKit/Classes/Cursors/FixedPageCursor.swift @@ -38,38 +38,26 @@ public class FixedPageCursor: CursorType where Cursor.LoadRe } public func loadNextBatch() -> Observable { - return Observable.create { [weak self] observer in - guard let strongSelf = self else { - observer.onError(CursorError.deallocated) - - return Disposables.create() - } - - if strongSelf.exhausted { + return Observable.create { observer in + if self.exhausted { observer.onError(CursorError.exhausted) return Disposables.create() } - let restOfLoaded = strongSelf.cursor.count - strongSelf.count + let restOfLoaded = self.cursor.count - self.count - if restOfLoaded >= strongSelf.pageSize || strongSelf.cursor.exhausted { - let startIndex = strongSelf.count - strongSelf.count += min(restOfLoaded, strongSelf.pageSize) + if restOfLoaded >= self.pageSize || self.cursor.exhausted { + let startIndex = self.count + self.count += min(restOfLoaded, self.pageSize) - observer.onNext(startIndex.. Observable in - guard let strongSelf = self else { - throw CursorError.deallocated - } - - return strongSelf.loadNextBatch() - } + return self.cursor.loadNextBatch() + .map { _ in self.loadNextBatch() } .subscribe() } } diff --git a/LeadKit/LeadKit/Classes/Cursors/MapCursor.swift b/LeadKit/LeadKit/Classes/Cursors/MapCursor.swift index c0d5f8a7..bb345382 100644 --- a/LeadKit/LeadKit/Classes/Cursors/MapCursor.swift +++ b/LeadKit/LeadKit/Classes/Cursors/MapCursor.swift @@ -58,15 +58,11 @@ public class MapCursor: CursorType where Cursor.LoadResul } public func loadNextBatch() -> Observable { - return cursor.loadNextBatch().map { [weak self] loadedRange -> LoadResultType in - guard let strongSelf = self else { - throw CursorError.deallocated - } + return cursor.loadNextBatch().map { loadedRange in + let startIndex = self.elements.count + self.elements += self.cursor[loadedRange].flatMap(self.transform) - let startIndex = strongSelf.elements.count - strongSelf.elements += strongSelf.cursor[loadedRange].flatMap(strongSelf.transform) - - return startIndex..: CursorType { } public func loadNextBatch() -> Observable { - return Observable.create { [weak self] observer in - guard let strongSelf = self else { - observer.onError(CursorError.deallocated) - - return Disposables.create() - } - - if strongSelf.exhausted { + return Observable.create { observer in + if self.exhausted { observer.onError(CursorError.exhausted) return Disposables.create() } - strongSelf.count = strongSelf.content.count + self.count = self.content.count - strongSelf.exhausted = true + self.exhausted = true - observer.onNext(0..