-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Kotlin and the libs for coroutines (#200)
* Migrated Project to Kotlin 1.5.30 * Updated scarlet-stream-adapter-coroutines to be compatible with 1.5.30 as well regarding use of asFlow and channels * Updated coroutines to 1.5.2 * scarlet-stream-adapter-coroutines produces hot flow and hot receive channel Fixes #169 Fixes #163 Fixes #27 * ChannelForwarder now calls dispose correctly on Completed and Error * Using new trySendBlocking in onNext callback * Updating Tests to include FlowStreamAdapterTest * Reving kotlin coroutines 1.6.0 * Updating circleci configuration to stash the correct test reports * Updating to coroutines 1.4 and higher removes the reactive streams behavior of the past Relied on a subscription and a buffered observer, adding buffering * Documentation * No need to rename files * Use supervisor job instead of globalscope * Proper variable naming * Channel Forwarder should not throw
- Loading branch information
1 parent
6d98e7d
commit 72dcb2a
Showing
17 changed files
with
400 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...-adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ChannelForwarder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.tinder.streamadapter.coroutines | ||
|
||
import com.tinder.scarlet.Stream | ||
import kotlinx.coroutines.channels.BufferOverflow | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.channels.ReceiveChannel | ||
import kotlinx.coroutines.channels.onClosed | ||
import kotlinx.coroutines.channels.onFailure | ||
import kotlinx.coroutines.channels.trySendBlocking | ||
|
||
internal class ChannelForwarder<T>(bufferSize: Int) : Stream.Observer<T> { | ||
private val channel = Channel<T>(bufferSize, BufferOverflow.DROP_OLDEST) | ||
private var disposable: Stream.Disposable? = null | ||
|
||
fun start(stream: Stream<T>): ReceiveChannel<T> { | ||
disposable = stream.start(this) | ||
return channel | ||
} | ||
|
||
override fun onComplete() { | ||
channel.close() | ||
disposable?.dispose() | ||
} | ||
|
||
override fun onError(throwable: Throwable) { | ||
channel.close(throwable) | ||
disposable?.dispose() | ||
} | ||
|
||
override fun onNext(data: T) { | ||
channel.trySendBlocking(data).onClosed { | ||
// ignore | ||
}.onFailure { | ||
// ignore | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...adapter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/FlowStreamAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED | ||
*/ | ||
|
||
package com.tinder.streamadapter.coroutines | ||
|
||
import com.tinder.scarlet.Stream | ||
import com.tinder.scarlet.StreamAdapter | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.buffer | ||
import kotlinx.coroutines.flow.receiveAsFlow | ||
|
||
class FlowStreamAdapter<T>(private val buffer: Int) : StreamAdapter<T, Flow<T>> { | ||
|
||
override fun adapt(stream: Stream<T>): Flow<T> { | ||
return ChannelForwarder<T>(buffer).start(stream).receiveAsFlow() | ||
} | ||
} |
14 changes: 6 additions & 8 deletions
14
...routines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
/* | ||
* © 2013 - 2018 Tinder, Inc., ALL RIGHTS RESERVED | ||
*/ | ||
|
||
package com.tinder.streamadapter.coroutines | ||
|
||
import com.tinder.scarlet.Stream | ||
import com.tinder.scarlet.StreamAdapter | ||
import kotlinx.coroutines.channels.ReceiveChannel | ||
import kotlinx.coroutines.reactive.openSubscription | ||
|
||
class ReceiveChannelStreamAdapter<T> : StreamAdapter<T, ReceiveChannel<T>> { | ||
class ReceiveChannelStreamAdapter<T>(private val buffer: Int) : StreamAdapter<T, ReceiveChannel<T>> { | ||
|
||
override fun adapt(stream: Stream<T>) = stream.openSubscription() | ||
} | ||
override fun adapt(stream: Stream<T>): ReceiveChannel<T> { | ||
val channelForwarder = ChannelForwarder<T>(buffer) | ||
return channelForwarder.start(stream) | ||
} | ||
} |
Oops, something went wrong.