File tree 3 files changed +63
-0
lines changed
3 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ package chrome.runtime
2
+
3
+ import kotlin.coroutines.experimental.Continuation
4
+
5
+ @Suppress(" NOTHING_TO_INLINE" )
6
+ inline fun <T > Continuation<T>.checkRuntimeAndResumeWith (result : T ) =
7
+ if (lastError == null ) {
8
+ resume(result)
9
+ } else {
10
+ resumeWithException(RuntimeException (lastError))
11
+ }
12
+
13
+ @Suppress(" NOTHING_TO_INLINE" )
14
+ inline fun Continuation<Unit>.checkRuntimeAndResume () =
15
+ if (lastError == null ) {
16
+ resume(Unit )
17
+ } else {
18
+ resumeWithException(RuntimeException (lastError))
19
+ }
Original file line number Diff line number Diff line change
1
+ package chrome.storage
2
+
3
+ import chrome.runtime.checkRuntimeAndResume
4
+ import chrome.runtime.checkRuntimeAndResumeWith
5
+ import kotlin.coroutines.experimental.suspendCoroutine
6
+
7
+ suspend fun StorageArea.getSync (keys : dynamic ) =
8
+ suspendCoroutine< dynamic > { continuation ->
9
+ get(keys) { continuation.checkRuntimeAndResumeWith(it) }
10
+ }
11
+
12
+ suspend fun StorageArea.setSync (items : dynamic ) =
13
+ suspendCoroutine<Unit > { continuation ->
14
+ set(items) { continuation.checkRuntimeAndResume() }
15
+ }
16
+
17
+ suspend fun StorageArea.removeSync (keys : dynamic ) =
18
+ suspendCoroutine<Unit > { continuation ->
19
+ remove(keys) { continuation.checkRuntimeAndResume() }
20
+ }
21
+
22
+ suspend fun StorageArea.clearSync () =
23
+ suspendCoroutine<Unit > { continuation ->
24
+ clear { continuation.checkRuntimeAndResume() }
25
+ }
Original file line number Diff line number Diff line change
1
+ package chrome.tabs
2
+
3
+ import chrome.runtime.checkRuntimeAndResumeWith
4
+ import kotlin.coroutines.experimental.suspendCoroutine
5
+
6
+ suspend fun querySync (queryInfo : QueryInfo ) =
7
+ suspendCoroutine<Array <Tab >> { continuation ->
8
+ query(queryInfo) { continuation.checkRuntimeAndResumeWith(it) }
9
+ }
10
+
11
+ suspend fun executeScriptSync (tabId : Int? , details : ExecuteScriptDetails ) =
12
+ suspendCoroutine< dynamic > { continuation ->
13
+ executeScript(tabId, details) { continuation.checkRuntimeAndResumeWith(it) }
14
+ }
15
+
16
+ suspend fun executeScriptSync (details : ExecuteScriptDetails ) =
17
+ suspendCoroutine< dynamic > { continuation ->
18
+ executeScript(details = details) { continuation.checkRuntimeAndResumeWith(it) }
19
+ }
You can’t perform that action at this time.
0 commit comments