Skip to content

Commit

Permalink
remove overdue deprecations and remove observable value tracking (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
cornerman authored Nov 10, 2023
1 parent feff7f1 commit 19a4bcf
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 254 deletions.
3 changes: 0 additions & 3 deletions colibri/src/main/scala/colibri/CanCancel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package colibri

trait CanCancel[-T] {
def unsafeCancel(cancelable: T): Unit

@deprecated("Use unsafeCancel instead", "0.2.7")
@inline final def cancel(cancelable: T): Unit = unsafeCancel(cancelable)
}
object CanCancel {
@inline def apply[T](implicit unsafeCancel: CanCancel[T]): CanCancel[T] = unsafeCancel
Expand Down
3 changes: 0 additions & 3 deletions colibri/src/main/scala/colibri/Cancelable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ trait Cancelable {
def isEmpty(): Boolean
def unsafeCancel(): Unit

@deprecated("Use unsafeCancel() instead", "0.2.7")
@inline final def cancel(): Unit = unsafeCancel()

final def cancelF[F[_]: Sync]: F[Unit] = Sync[F].delay(unsafeCancel())
final def cancelIO: IO[Unit] = cancelF[IO]
final def cancelSyncIO: SyncIO[Unit] = cancelF[SyncIO]
Expand Down
48 changes: 9 additions & 39 deletions colibri/src/main/scala/colibri/Connectable.scala
Original file line number Diff line number Diff line change
@@ -1,55 +1,25 @@
package colibri

final class Connectable[+T] private (val value: T, val connect: () => Cancelable) {
def map[A](f: T => A): Connectable[A] = new Connectable(f(value), connect)
final class Connectable[+T] private (val value: T, val unsafeConnect: () => Cancelable) {
def map[A](f: T => A): Connectable[A] = new Connectable(f(value), unsafeConnect)
def flatMap[A](f: T => Connectable[A]): Connectable[A] = {
val connectable = f(value)
new Connectable(connectable.value, () => Cancelable.composite(connect(), connectable.connect()))
new Connectable(connectable.value, () => Cancelable.composite(unsafeConnect(), connectable.unsafeConnect()))
}
}
object Connectable {
def apply[T](value: T, connect: () => Cancelable) = {
val cancelable = Cancelable.refCount(connect)
def apply[T](value: T, unsafeConnect: () => Cancelable) = {
val cancelable = Cancelable.refCount(unsafeConnect)
new Connectable(value, cancelable.ref)
}

@inline implicit class ConnectableObservableOperations[A](val source: Connectable[Observable[A]]) extends AnyVal {
def refCount: Observable[A] = new Observable[A] {
def unsafeSubscribe(sink: Observer[A]): Cancelable = Cancelable.composite(source.value.unsafeSubscribe(sink), source.connect())
def unsafeSubscribe(sink: Observer[A]): Cancelable = Cancelable.composite(source.value.unsafeSubscribe(sink), source.unsafeConnect())
}
@deprecated("Use unsafeHot instead", "0.5.0")
def hot: Observable.Hot[A] = unsafeHot()
def unsafeHot(): Observable.Hot[A] = new Observable.Hot[A] {
val cancelable = source.connect()
def unsafeSubscribe(sink: Observer[A]): Cancelable = source.value.unsafeSubscribe(sink)
}
}

@inline implicit class ConnectableObservableValueOperations[A](val source: Connectable[Observable.Value[A]]) extends AnyVal {
def refCount: Observable.Value[A] = new Observable.Value[A] {
def now() = source.value.now()
def unsafeSubscribe(sink: Observer[A]): Cancelable = Cancelable.composite(source.value.unsafeSubscribe(sink), source.connect())
}
@deprecated("Use unsafeHot instead", "0.7.8")
def hot: Observable.HotValue[A] = unsafeHot()
def unsafeHot(): Observable.HotValue[A] = new Observable.HotValue[A] {
val cancelable = source.connect()
def now() = source.value.now()
def unsafeSubscribe(sink: Observer[A]): Cancelable = source.value.unsafeSubscribe(sink)
}
}

@inline implicit class ConnectableObservableMaybeValueOperations[A](val source: Connectable[Observable.MaybeValue[A]]) extends AnyVal {
def refCount: Observable.MaybeValue[A] = new Observable.MaybeValue[A] {
def now() = source.value.now()
def unsafeSubscribe(sink: Observer[A]): Cancelable = Cancelable.composite(source.value.unsafeSubscribe(sink), source.connect())
}
@deprecated("Use unsafeHot instead", "0.7.8")
def hot: Observable.HotMaybeValue[A] = unsafeHot()
def unsafeHot(): Observable.HotMaybeValue[A] = new Observable.HotMaybeValue[A] {
val cancelable = source.connect()
def now() = source.value.now()
def unsafeSubscribe(sink: Observer[A]): Cancelable = source.value.unsafeSubscribe(sink)
def unsafeHot(): Observable[A] = {
val _ = source.unsafeConnect()
source.value
}
}
}
Loading

0 comments on commit 19a4bcf

Please sign in to comment.