Skip to content
This repository has been archived by the owner on Jul 8, 2022. It is now read-only.

Commit

Permalink
Sync from next
Browse files Browse the repository at this point in the history
  • Loading branch information
soywiz committed Jan 27, 2021
1 parent eeab7b4 commit 88f645e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions korio/src/commonMain/kotlin/com/soywiz/korio/lang/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ internal expect object EnvironmentInternal {
}

@ThreadLocal
private var customEnvironments = LinkedHashMap<String, String>()
private var customEnvironments: LinkedHashMap<String, String>? = null

object Environment {
// Uses querystring on JS/Browser, and proper env vars in the rest
operator fun get(key: String): String? = customEnvironments[key] ?: EnvironmentInternal[key]
operator fun get(key: String): String? = customEnvironments?.get(key) ?: EnvironmentInternal[key]
operator fun set(key: String, value: String) {
customEnvironments[key] = value
if (customEnvironments != null) {
customEnvironments = LinkedHashMap()
}
customEnvironments?.set(key, value)
}

fun getAll(): Map<String, String> = customEnvironments + EnvironmentInternal.getAll()
fun getAll(): Map<String, String> = (customEnvironments ?: mapOf()) + EnvironmentInternal.getAll()
}

fun Environment.expand(str: String): String {
Expand Down

0 comments on commit 88f645e

Please sign in to comment.