Skip to content

Conversation

@andersio
Copy link
Member

@andersio andersio commented May 5, 2017

Cherry-picked from #334.

Use ActionDisposable instead, akin to Signal.observe.

@andersio andersio modified the milestone: 2.0 May 8, 2017
return DisposableHandle.empty
return disposable.flatMap { disposable in
return disposables.modify { disposables in
let token = disposables!.insert(disposable)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this ! is safe. This could have been disposed between the above check and here.

} else {
d.dispose()
return DisposableHandle.empty
return disposable.flatMap { disposable in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous guard structure is preferable to disposable.flatMap to reduce the nesting by a level.

public func add(_ d: Disposable?) -> DisposableHandle {
guard let d = d else {
return DisposableHandle.empty
public func add(_ disposable: Disposable?) -> Disposable? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could leave this as non-optional by returning a disposable that does nothing. I'm not sure which would be better. Is there a particular reason you decided to return an optional?

Copy link
Member Author

@andersio andersio May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It follows the precedence of Signal.observe, and the fact that CompositeDisposable.add accepts Disposable?.

The disposable array can be cleared at any time, since the disposal may happen after checking `isDisposed` but before accessing `disposables`.
@andersio andersio force-pushed the remove-disposable-handle branch from 81d0409 to 5ae1247 Compare May 11, 2017 08:39
@andersio andersio requested a review from mdiep May 11, 2017 08:41
@mdiep mdiep merged commit fd9295f into master May 11, 2017
@mdiep mdiep deleted the remove-disposable-handle branch May 11, 2017 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants