Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swift Concurrencyでのスケジュール処理を考える / Mobile Act OS...
Search
Yutaro Muta
November 28, 2025
Technology
0
120
Swift Concurrencyでのスケジュール処理を考える / Mobile Act OSAKA 17
Mobile Act OSAKA 17
https://mobileact.connpass.com/event/374447/
Yutaro Muta
November 28, 2025
Tweet
Share
More Decks by Yutaro Muta
See All by Yutaro Muta
猫と暮らすネットワークカメラ生活🐈 ~Vision frameworkでペットを愛でよう~ / iOSDC Japan 2025
yutailang0119
0
350
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
270
Swiftの “private” を テストする / Testing Swift "private"
yutailang0119
0
310
Apple Vision Pro購入RTA 1泊3日弾丸ハワイツアー / RTA: Purchase Apple Vision Pro in Hawaii
yutailang0119
0
1.5k
個人開発のたのしみ / Enjoying personal development
yutailang0119
0
1.1k
バックポートして学ぶ新APIの仕組み
yutailang0119
0
3.2k
Backport AsyncImage
yutailang0119
0
780
xcrun Essentials
yutailang0119
6
1.4k
Let's Coding SwiftUI on iPad!
yutailang0119
1
550
Other Decks in Technology
See All in Technology
仕様書駆動AI開発の実践: Issue→Skill→PRテンプレで 再現性を作る
knishioka
2
680
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
6
68k
Oracle Cloud Observability and Management Platform - OCI 運用監視サービス概要 -
oracle4engineer
PRO
2
14k
What happened to RubyGems and what can we learn?
mikemcquaid
0
310
Claude_CodeでSEOを最適化する_AI_Ops_Community_Vol.2__マーケティングx_AIはここまで進化した.pdf
riku_423
2
610
外部キー制約の知っておいて欲しいこと - RDBMSを正しく使うために必要なこと / FOREIGN KEY Night
soudai
PRO
12
5.6k
[CV勉強会@関東 World Model 読み会] Orbis: Overcoming Challenges of Long-Horizon Prediction in Driving World Models (Mousakhan+, NeurIPS 2025)
abemii
0
150
ファインディの横断SREがTakumi byGMOと取り組む、セキュリティと開発スピードの両立
rvirus0817
1
1.6k
AIと新時代を切り拓く。これからのSREとメルカリIBISの挑戦
0gm
2
3k
プロポーザルに込める段取り八分
shoheimitani
1
590
生成AIを活用した音声文字起こしシステムの2つの構築パターンについて
miu_crescent
PRO
3
210
Amazon S3 Vectorsを使って資格勉強用AIエージェントを構築してみた
usanchuu
3
450
Featured
See All Featured
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
120
Code Reviewing Like a Champion
maltzj
527
40k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
93
The Cost Of JavaScript in 2023
addyosmani
55
9.5k
New Earth Scene 8
popppiees
1
1.5k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
450
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
430
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
330
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
280
Transcript
Swift Concurrencyでの スケジュール処理を考える id:yutailang0119 / @yutailang0119 2025/11/28 Mobile Act Osaka
17 1
yutailang0119 • 株式会社はてな ◦ @京都オフィス ◦ アプリケーションエンジニア ◦ サービスプラットフォームチーム •
try! Swift Tokyo Organizer ◦ 2026チケット販売中 • AVP座談会 🥽 2
3 Swift Concurrencyの スケジュール処理といえば?
4 https://zenn.dev/treastrain/articles/a78b5f892f4654
🔁 Swift Concurrency 時代の 「n秒ごとに処理を実行する」 • AsyncTimerSequence • AsyncStream +
Task.sleep • ... 5
6 「n秒ごとに処理を実行する」 = タスク開始時点で 全ての時機が決まっている
7 今回のお題
今回のお題 8 • タスク⓪後、タスク ①の時機が決まる ◦ タスク①の実行を予約 • タスク①後、タスク ②の時機が決まる
◦ 処理②の実行を予約 • …
9 https://fortee.jp/iosdc-japan-2025/proposal/292e2ec3-d74b-49a6-a8cb-63c2883d589e
Smart Device Management API 10 • WebRTCセッションの確立 ◦ sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream ◦
ライブストリームのセッション有効期間は5分 ◦ レスポンスに expiresAt がやってくる • セッションを延長可能 ◦ sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream
Smart Device Management API 11 • WebRTCセッションの確立 ◦ sdm.devices.commands.CameraLiveStream.GenerateWebRtcStream ◦
ライブストリームのセッション有効期間は5分 ◦ レスポンスに expiresAt がやってくる • セッションを延長可能 ◦ sdm.devices.commands.CameraLiveStream.ExtendWebRtcStream
今回のお題 12 • セッション確立後、延長タスク ①の時機が決まる ◦ 延長処理①の実行を予約 • 延長処理①後、延長タスク ②の時機が決まる
◦ 延長処理②の実行を予約 • …
13 今回のお題 「Task終了時に次Taskを予約」
14 TaskScheduler
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 } } } }
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() } } } }
TaskScheduler 17 • Task内部キャンセルはErrorで表現 • 外からのキャンセルも可能にする ◦ task.cancel() ◦ セッションを止めたら、延長予約もキャンセル
• 実際には expiresAt に実行では遅い ◦ expiresAt?.addingTimeInterval(-60)
18 まとめ
まとめ 19 • スケジューリング用途によって手法は異なる ◦ タスク開始時点で全ての時機が決まっている ◦ 処理後に次のタスク実行タイミングが決まる • Swift
ConcurrencyでのScheduler (Worker) 処理を紹介