forked from Tinder/Scarlet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Updated scarlet-stream-adapter-coroutines to be compatible with 1.5.30 as well regarding use of asFlow and channels
- Loading branch information
1 parent
6d98e7d
commit e5bbbe9
Showing
10 changed files
with
80 additions
and
39 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
17 changes: 17 additions & 0 deletions
17
...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,17 @@ | ||
/* | ||
* © 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.reactive.asFlow | ||
|
||
class FlowStreamAdapter<T> : StreamAdapter<T, Flow<T>> { | ||
|
||
override fun adapt(stream: Stream<T>): Flow<T> { | ||
return (stream as Stream<Any>).asFlow() as Flow<T> | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ter-coroutines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelAdapter.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,33 @@ | ||
package com.tinder.streamadapter.coroutines | ||
|
||
import com.tinder.scarlet.Stream | ||
import com.tinder.scarlet.StreamAdapter | ||
import kotlinx.coroutines.channels.Channel | ||
import kotlinx.coroutines.channels.ReceiveChannel | ||
import kotlinx.coroutines.channels.sendBlocking | ||
|
||
class ReceiveChannelAdapter<T> : StreamAdapter<T, ReceiveChannel<T>> { | ||
|
||
override fun adapt(stream: Stream<T>): ReceiveChannel<T> { | ||
val channelForwarder = ChannelForwarder<T>() | ||
stream.start(channelForwarder) | ||
return channelForwarder.channel | ||
} | ||
|
||
private class ChannelForwarder<T> : Stream.Observer<T> { | ||
private val _channel = Channel<T>() | ||
val channel: ReceiveChannel<T> = _channel | ||
|
||
override fun onComplete() { | ||
_channel.close() | ||
} | ||
|
||
override fun onError(throwable: Throwable) { | ||
_channel.close(throwable) | ||
} | ||
|
||
override fun onNext(data: T) { | ||
_channel.sendBlocking(data) | ||
} | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
...routines/src/main/java/com/tinder/streamadapter/coroutines/ReceiveChannelStreamAdapter.kt
This file was deleted.
Oops, something went wrong.