mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-03-12 14:38:15 +00:00
Reorder functions in PoTokenWebView
This commit is contained in:
parent
53b599b042
commit
87317c6faf
@ -177,44 +177,6 @@ class PoTokenWebView private constructor(
|
|||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
//region Handling multiple emitters
|
|
||||||
/**
|
|
||||||
* Adds the ([identifier], [emitter]) pair to the [poTokenEmitters] list. This makes it so that
|
|
||||||
* multiple poToken requests can be generated invparallel, and the results will be notified to
|
|
||||||
* the right emitters.
|
|
||||||
*/
|
|
||||||
private fun addPoTokenEmitter(identifier: String, emitter: SingleEmitter<String>) {
|
|
||||||
synchronized(poTokenEmitters) {
|
|
||||||
poTokenEmitters.add(Pair(identifier, emitter))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts and removes from the [poTokenEmitters] list a [SingleEmitter] based on its
|
|
||||||
* [identifier]. The emitter is supposed to be used immediately after to either signal a success
|
|
||||||
* or an error.
|
|
||||||
*/
|
|
||||||
private fun popPoTokenEmitter(identifier: String): SingleEmitter<String>? {
|
|
||||||
return synchronized(poTokenEmitters) {
|
|
||||||
poTokenEmitters.indexOfFirst { it.first == identifier }.takeIf { it >= 0 }?.let {
|
|
||||||
poTokenEmitters.removeAt(it).second
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clears [poTokenEmitters] and returns its previous contents. The emitters are supposed to be
|
|
||||||
* used immediately after to either signal a success or an error.
|
|
||||||
*/
|
|
||||||
private fun popAllPoTokenEmitters(): List<Pair<String, SingleEmitter<String>>> {
|
|
||||||
return synchronized(poTokenEmitters) {
|
|
||||||
val result = poTokenEmitters.toList()
|
|
||||||
poTokenEmitters.clear()
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region Obtaining poTokens
|
//region Obtaining poTokens
|
||||||
override fun generatePoToken(identifier: String): Single<String> =
|
override fun generatePoToken(identifier: String): Single<String> =
|
||||||
Single.create { emitter ->
|
Single.create { emitter ->
|
||||||
@ -281,6 +243,44 @@ class PoTokenWebView private constructor(
|
|||||||
}
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
|
//region Handling multiple emitters
|
||||||
|
/**
|
||||||
|
* Adds the ([identifier], [emitter]) pair to the [poTokenEmitters] list. This makes it so that
|
||||||
|
* multiple poToken requests can be generated invparallel, and the results will be notified to
|
||||||
|
* the right emitters.
|
||||||
|
*/
|
||||||
|
private fun addPoTokenEmitter(identifier: String, emitter: SingleEmitter<String>) {
|
||||||
|
synchronized(poTokenEmitters) {
|
||||||
|
poTokenEmitters.add(Pair(identifier, emitter))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts and removes from the [poTokenEmitters] list a [SingleEmitter] based on its
|
||||||
|
* [identifier]. The emitter is supposed to be used immediately after to either signal a success
|
||||||
|
* or an error.
|
||||||
|
*/
|
||||||
|
private fun popPoTokenEmitter(identifier: String): SingleEmitter<String>? {
|
||||||
|
return synchronized(poTokenEmitters) {
|
||||||
|
poTokenEmitters.indexOfFirst { it.first == identifier }.takeIf { it >= 0 }?.let {
|
||||||
|
poTokenEmitters.removeAt(it).second
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears [poTokenEmitters] and returns its previous contents. The emitters are supposed to be
|
||||||
|
* used immediately after to either signal a success or an error.
|
||||||
|
*/
|
||||||
|
private fun popAllPoTokenEmitters(): List<Pair<String, SingleEmitter<String>>> {
|
||||||
|
return synchronized(poTokenEmitters) {
|
||||||
|
val result = poTokenEmitters.toList()
|
||||||
|
poTokenEmitters.clear()
|
||||||
|
result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
//region Utils
|
//region Utils
|
||||||
/**
|
/**
|
||||||
* Makes a POST request to [url] with the given [data] by setting the correct headers. Calls
|
* Makes a POST request to [url] with the given [data] by setting the correct headers. Calls
|
||||||
|
Loading…
x
Reference in New Issue
Block a user