Skip to content

Commit cd11232

Browse files
committed
Clean SpotifyRestAction
1 parent 3dcb589 commit cd11232

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/main/kotlin/com/adamratzman/spotify/utils/SpotifyRestAction.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ class SpotifyRestAction<T>(private val api: SpotifyAPI, private val supplier: Su
1414
}
1515
}
1616

17-
fun queue(consumer: (T) -> Unit) = api.executor.execute { consumer(complete()) }
17+
fun queue(consumer: ((T) -> Unit)) = queue(consumer, {})
18+
19+
fun queue(consumer: ((T) -> Unit), failure: ((Throwable) -> Unit)) {
20+
api.executor.execute {
21+
try {
22+
val result = complete()
23+
consumer(result)
24+
} catch (t: Throwable) {
25+
failure(t)
26+
}
27+
}
28+
}
29+
1830
fun asFuture() = CompletableFuture.supplyAsync(supplier)
31+
1932
fun queueAfter(quantity: Int, timeUnit: TimeUnit = TimeUnit.SECONDS, consumer: (T) -> Unit) {
2033
val runAt = System.currentTimeMillis() + timeUnit.toMillis(quantity.toLong())
2134
queue { result ->

0 commit comments

Comments
 (0)