Last active
July 22, 2019 13:34
-
-
Save RBusarow/4a3bc4d88bcc06c1805f70df66898246 to your computer and use it in GitHub Desktop.
Re-imagined CoroutineContext as a decorator around a standard map.
This file contains hidden or 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
class CoroutineContext { | |
internal val map = mutableMapOf<Key<*>, Element>() | |
operator fun <E : Element> get(key: Key<E>): E? = map[key] as? E | |
operator fun plus(context: CoroutineContext): CoroutineContext { | |
val new = CoroutineContext() | |
new.map.putAll(map) | |
new.map.putAll(context.map) | |
return new | |
} | |
interface Key<E : Element> | |
interface Element | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment