Skip to content

Instantly share code, notes, and snippets.

@Dico200
Dico200 / BehaviorSubjectChannel.kt
Last active March 25, 2019 02:55
BehaviorSubjectChannel - assuming that means buffering the last element in a broadcast channel for new subscriptions
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
class BehaviorSubjectChannel<E>(val del: BroadcastChannel<E>, context: CoroutineContext? = null) : BroadcastChannel<E> by del {
@Volatile
private var hasElem: Boolean = false
@Volatile
private var lastElem: E? = null
@Dico200
Dico200 / mppTools.kt
Created January 18, 2019 02:30
Kotlin Multiplatform Project dsl tools for (for Kotlin version 1.3.11)
@file:Suppress("UNCHECKED_CAST")
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.get
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.plugin.mpp.*
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultKotlinSourceSet
import kotlin.reflect.KProperty
@Dico200
Dico200 / localCoroutineContext.kt
Last active October 16, 2018 14:41
Code to access CoroutineContext from non-suspend functions
package io.dico.parcels2.util
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
/**
* Return the context of the coroutine that (directly or indirectly) called this function.
* Does not work when the thread is changed.
*
* Requires that the coroutine context contains [CoroutineContextStoringElement] to work.
@Dico200
Dico200 / implementation-by-delegation-changes.md
Last active September 13, 2018 09:37
Changes to Implementation by delegation

Implementation by delegation enhancements

  • Type: Design proposal
  • Author: Dico Karssiens
  • Contributors: []
  • Status: Submitted
  • Prototype: Not implemented, but I would be happy to do so

//Fill in issue below once created.
Discussion of this proposal is held in this issue.