Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥

Swift Concurrencyでのスケジュール処理を考える / Mobile Act OS...

Avatar for Yutaro Muta Yutaro Muta
November 28, 2025

Swift Concurrencyでのスケジュール処理を考える / Mobile Act OSAKA 17

Avatar for Yutaro Muta

Yutaro Muta

November 28, 2025
Tweet

More Decks by Yutaro Muta

Other Decks in Technology

Transcript

  1. Smart Device Management API 10 • WebRTCセッションの確立 ◦ sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream ◦

    ライブストリームのセッション有効期間は5分 ◦ レスポンスに expiresAt がやってくる • セッションを延長可能 ◦ sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream
  2. Smart Device Management API 11 • WebRTCセッションの確立 ◦ sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream ◦

    ライブストリームのセッション有効期間は5分 ◦ レスポンスに expiresAt がやってくる • セッションを延長可能 ◦ sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream
  3. TaskScheduler 15 actor TaskScheduler { private let task: Task<Void, Error>

    init(first: Date?) { task = Task { var _next = first while let next = _next { let interval = max(0, next.timeIntervalSinceNow) try await Task.sleep(nanoseconds: UInt64(interval * 1_000_000_000)) try Task.checkCancellation() ... let response = try await client.request(for: request) _next = response.results.expiresAt } } } }
  4. TaskScheduler (汎用化) 16 actor TaskScheduler { private let task: Task<Void,

    Error> init(first: Date?, action: @escaping @Sendable () async throws -> Date?) { task = Task { var _next = first while let next = _next { let interval = max(0, next.timeIntervalSinceNow) try await Task.sleep(nanoseconds: UInt64(interval * 1_000_000_000)) try Task.checkCancellation() _next = try await action() } } } }