Skip to content

Instantly share code, notes, and snippets.

@eungju
Last active August 29, 2017 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eungju/f0144d9bd97fb5d6e8893e9a1150713b to your computer and use it in GitHub Desktop.
Save eungju/f0144d9bd97fb5d6e8893e9a1150713b to your computer and use it in GitHub Desktop.
Rx에서 reactive base type 만들 때 자주 하는 실수
override fun connectDevice(userDeviceRef: UserDeviceRef, deviceAttributes: DeviceAttributes, nodeRef: PilsnerRef): Completable
= Completable.fromRunnable {
rwLock.write {
devicePresences[userDeviceRef.deviceId] = Presence(userDeviceRef, deviceAttributes, nodeRef)
userDevices.put(userDeviceRef.userId, userDeviceRef.deviceId)
}
}
override fun getPresencesOfUser(userId: UserId): Single<List<Presence>>
= Single.fromCallable {
rwLock.read {
val deviceIds = userDevices.get(userId)
deviceIds.mapNotNull { devicePresences[it] }
}
}
override fun connectDevice(userDeviceRef: UserDeviceRef, deviceAttributes: DeviceAttributes, nodeRef: PilsnerRef): Completable
= rwLock.write {
devicePresences[userDeviceRef.deviceId] = Presence(userDeviceRef, deviceAttributes, nodeRef)
userDevices.put(userDeviceRef.userId, userDeviceRef.deviceId)
}.let { Completable.complete() }
override fun getPresencesOfUser(userId: UserId): Single<List<Presence>>
= rwLock.read {
val deviceIds = userDevices.get(userId)
deviceIds.mapNotNull { devicePresences[it] }
}.let { Single.just(it) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment