Skip to content

Commit 99846f5

Browse files
committed
Added @mainactor attribute to all async functions
I've got a crash when using async functions - as they were executed in background thread. See SvenTiigi#79
1 parent a914b98 commit 99846f5

5 files changed

+14
-0
lines changed

Sources/API/YouTubePlayer+PlaybackAPI.swift

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public extension YouTubePlayer {
1919

2020
#if compiler(>=5.5) && canImport(_Concurrency)
2121
/// Returns a number between 0 and 1 that specifies the percentage of the video that the player shows as buffered
22+
@MainActor
2223
func getVideoLoadedFraction() async throws -> Double {
2324
try await withCheckedThrowingContinuation { continuation in
2425
self.getVideoLoadedFraction(completion: continuation.resume)
@@ -79,6 +80,7 @@ public extension YouTubePlayer {
7980

8081
#if compiler(>=5.5) && canImport(_Concurrency)
8182
/// Returns the PlaybackState of the player video
83+
@MainActor
8284
func getPlaybackState() async throws -> PlaybackState {
8385
try await withCheckedThrowingContinuation { continuation in
8486
self.getPlaybackState(completion: continuation.resume)
@@ -100,6 +102,7 @@ public extension YouTubePlayer {
100102

101103
#if compiler(>=5.5) && canImport(_Concurrency)
102104
/// Returns the elapsed time in seconds since the video started playing
105+
@MainActor
103106
func getCurrentTime() async throws -> Double {
104107
try await withCheckedThrowingContinuation { continuation in
105108
self.getCurrentTime(completion: continuation.resume)
@@ -159,6 +162,7 @@ public extension YouTubePlayer {
159162

160163
#if compiler(>=5.5) && canImport(_Concurrency)
161164
/// Returns the current PlaybackMetadata
165+
@MainActor
162166
func getPlaybackMetadata() async throws -> PlaybackMetadata {
163167
try await withCheckedThrowingContinuation { continuation in
164168
self.getPlaybackMetadata(completion: continuation.resume)

Sources/API/YouTubePlayer+PlaybackRateAPI.swift

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public extension YouTubePlayer {
1818

1919
#if compiler(>=5.5) && canImport(_Concurrency)
2020
/// This function retrieves the playback rate of the currently playing video
21+
@MainActor
2122
func getPlaybackRate() async throws -> PlaybackRate {
2223
try await withCheckedThrowingContinuation { continuation in
2324
self.getPlaybackRate(completion: continuation.resume)
@@ -52,6 +53,7 @@ public extension YouTubePlayer {
5253

5354
#if compiler(>=5.5) && canImport(_Concurrency)
5455
/// This function returns the set of playback rates in which the current video is available
56+
@MainActor
5557
func getAvailablePlaybackRates() async throws -> [PlaybackRate] {
5658
try await withCheckedThrowingContinuation { continuation in
5759
self.getAvailablePlaybackRates(completion: continuation.resume)

Sources/API/YouTubePlayer+PlaylistAPI.swift

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public extension YouTubePlayer {
7373

7474
#if compiler(>=5.5) && canImport(_Concurrency)
7575
/// This function returns an array of the video IDs in the playlist as they are currently ordered
76+
@MainActor
7677
func getPlaylist() async throws -> [String] {
7778
try await withCheckedThrowingContinuation { continuation in
7879
self.getPlaylist(completion: continuation.resume)
@@ -94,6 +95,7 @@ public extension YouTubePlayer {
9495

9596
#if compiler(>=5.5) && canImport(_Concurrency)
9697
/// This function returns the index of the playlist video that is currently playing.
98+
@MainActor
9799
func getPlaylistIndex() async throws -> Int {
98100
try await withCheckedThrowingContinuation { continuation in
99101
self.getPlaylistIndex(completion: continuation.resume)

Sources/API/YouTubePlayer+VideoInformationAPI.swift

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public extension YouTubePlayer {
3636

3737
#if compiler(>=5.5) && canImport(_Concurrency)
3838
/// Retrieve the YouTubePlayer Information
39+
@MainActor
3940
func getInformation() async throws -> Information {
4041
try await withCheckedThrowingContinuation { continuation in
4142
self.getInformation(completion: continuation.resume)
@@ -57,6 +58,7 @@ public extension YouTubePlayer {
5758

5859
#if compiler(>=5.5) && canImport(_Concurrency)
5960
/// Returns the duration in seconds of the currently playing video
61+
@MainActor
6062
func getDuration() async throws -> Double {
6163
try await withCheckedThrowingContinuation { continuation in
6264
self.getDuration(completion: continuation.resume)
@@ -96,6 +98,7 @@ public extension YouTubePlayer {
9698

9799
#if compiler(>=5.5) && canImport(_Concurrency)
98100
/// Returns the YouTube.com URL for the currently loaded/playing video
101+
@MainActor
99102
func getVideoURL() async throws -> String {
100103
try await withCheckedThrowingContinuation { continuation in
101104
self.getVideoURL(completion: continuation.resume)
@@ -117,6 +120,7 @@ public extension YouTubePlayer {
117120

118121
#if compiler(>=5.5) && canImport(_Concurrency)
119122
/// Returns the embed code for the currently loaded/playing video
123+
@MainActor
120124
func getVideoEmbedCode() async throws -> String {
121125
try await withCheckedThrowingContinuation { continuation in
122126
self.getVideoEmbedCode(completion: continuation.resume)

Sources/API/YouTubePlayer+VolumeAPI.swift

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public extension YouTubePlayer {
3232

3333
#if compiler(>=5.5) && canImport(_Concurrency)
3434
/// Returns Bool value if the player is muted
35+
@MainActor
3536
func isMuted() async throws -> Bool {
3637
try await withCheckedThrowingContinuation { continuation in
3738
self.isMuted(completion: continuation.resume)
@@ -53,6 +54,7 @@ public extension YouTubePlayer {
5354

5455
#if compiler(>=5.5) && canImport(_Concurrency)
5556
/// Returns the player's current volume, an integer between 0 and 100
57+
@MainActor
5658
func getVolume() async throws -> Int {
5759
try await withCheckedThrowingContinuation { continuation in
5860
self.getVolume(completion: continuation.resume)

0 commit comments

Comments
 (0)