File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed
kotlinx-coroutines-core-js/src/main/kotlin/kotlinx/coroutines/experimental Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2016-2017 JetBrains s.r.o.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org.w3c.performance
18+
19+ public abstract class Performance {
20+ abstract fun now (): Double
21+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2016-2017 JetBrains s.r.o.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package org.w3c.dom
18+
19+ public abstract class Window
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright 2016-2017 JetBrains s.r.o.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package kotlinx.coroutines.experimental
18+
19+ import org.w3c.dom.Window
20+
21+ /* *
22+ * Suspends coroutine until next JS animation frame and returns frame time on resumption.
23+ * The time is consistent with [window.performance.now()][org.w3c.performance.Performance.now].
24+ * This function is cancellable. If the [Job] of the current coroutine is completed while this suspending
25+ * function is waiting, this function immediately resumes with [CancellationException].
26+ */
27+ public suspend fun Window.awaitAnimationFrame (): Double = suspendCancellableCoroutine { cont ->
28+ val handle = requestAnimationFrame { timestamp ->
29+ with (cont) { DefaultDispatcher .resumeUndispatched(timestamp) }
30+ }
31+ cont.invokeOnCompletion {
32+ cancelAnimationFrame(handle)
33+ }
34+ }
You can’t perform that action at this time.
0 commit comments