RACSerialDisposable.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // RACSerialDisposable.h
  3. // ReactiveCocoa
  4. //
  5. // Created by Justin Spahr-Summers on 2013-07-22.
  6. // Copyright (c) 2013 GitHub, Inc. All rights reserved.
  7. //
  8. #import "RACDisposable.h"
  9. /// A disposable that contains exactly one other disposable and allows it to be
  10. /// swapped out atomically.
  11. @interface RACSerialDisposable : RACDisposable
  12. /// The inner disposable managed by the serial disposable.
  13. ///
  14. /// This property is thread-safe for reading and writing. However, if you want to
  15. /// read the current value _and_ write a new one atomically, use
  16. /// -swapInDisposable: instead.
  17. ///
  18. /// Disposing of the receiver will also dispose of the current disposable set for
  19. /// this property, then set the property to nil. If any new disposable is set
  20. /// after the receiver is disposed, it will be disposed immediately and this
  21. /// property will remain set to nil.
  22. @property (atomic, strong) RACDisposable *disposable;
  23. /// Creates a serial disposable which will wrap the given disposable.
  24. ///
  25. /// disposable - The value to set for `disposable`. This may be nil.
  26. ///
  27. /// Returns a RACSerialDisposable, or nil if an error occurs.
  28. + (instancetype)serialDisposableWithDisposable:(RACDisposable *)disposable;
  29. /// Atomically swaps the receiver's `disposable` for `newDisposable`.
  30. ///
  31. /// newDisposable - The new value for `disposable`. If the receiver has already
  32. /// been disposed, this disposable will be too, and `disposable`
  33. /// will remain set to nil. This argument may be nil.
  34. ///
  35. /// Returns the previous value for the `disposable` property.
  36. - (RACDisposable *)swapInDisposable:(RACDisposable *)newDisposable;
  37. @end