Kotlin Coroutines Freelance IT
Kotlin Coroutines Freelance IT Career Async suspend launch async Flow Dispatcher Android Ktor Spring Boot Portfolio Upwork
| Concept | Function | Use Case | Thread |
|---|---|---|---|
| suspend | หยุดชั่วคราว ไม่ Block | Network Database File I/O | ไม่ Block Thread |
| launch | Fire-and-forget | Update UI Send Event | ตาม Dispatcher |
| async/await | Return Deferred | Parallel Requests | ตาม Dispatcher |
| Flow | Reactive Stream | Realtime Updates Search | Collect บน Main |
| Channel | Coroutine Communication | Producer-Consumer | ตาม Dispatcher |
Coroutines Basics
// === Kotlin Coroutines Examples ===
// Basic suspend function
// suspend fun fetchUser(id: Int): User {
// return withContext(Dispatchers.IO) {
// api.getUser(id) // Network call on IO thread
// }
// }
//
// // Launch coroutine (Android ViewModel)
// class UserViewModel : ViewModel() {
// private val _user = MutableStateFlow(null)
// val user: StateFlow = _user.asStateFlow()
//
// fun loadUser(id: Int) {
// viewModelScope.launch {
// try {
// _user.value = fetchUser(id)
// } catch (e: Exception) {
// _error.value = e.message
// }
// }
// }
// }
//
// // Parallel async calls
// suspend fun loadProfile(userId: Int): Profile {
// return coroutineScope {
// val user = async { fetchUser(userId) }
// val posts = async { fetchPosts(userId) }
// val followers = async { fetchFollowers(userId) }
// Profile(user.await(), posts.await(), followers.await())
// }
// }
//
// // Flow for reactive streams
// fun searchUsers(query: String): Flow<List<User>> = flow {
// val results = api.search(query)
// emit(results)
// }.flowOn(Dispatchers.IO)
//
// // Collect in UI
// lifecycleScope.launch {
// viewModel.searchUsers("kotlin")
// .debounce(300)
// .distinctUntilChanged()
// .collect { users -> adapter.submitList(users) }
// }
from dataclasses import dataclass
@dataclass
class CoroutinePattern:
pattern: str
code: str
use_case: str
dispatcher: str
patterns = [
CoroutinePattern("Sequential Calls",
"val a = fetchA(); val b = fetchB(a.id)",
"API ที่ต้องเรียกตามลำดับ (Dependent)",
"Dispatchers.IO"),
CoroutinePattern("Parallel Calls",
"val a = async { fetchA() }; val b = async { fetchB() }; use(a.await(), b.await())",
"API อิสระ เรียกพร้อมกัน (Independent)",
"Dispatchers.IO"),
CoroutinePattern("Flow Collection",
"flow { emit(data) }.flowOn(IO).collect { update(it) }",
"Reactive Stream Realtime Updates Search",
"flowOn(IO) collect(Main)"),
CoroutinePattern("Error Handling",
"try { fetchData() } catch (e: Exception) { handleError(e) }",
"จัดการ Error เหมือน Synchronous Code",
"ทุก Dispatcher"),
CoroutinePattern("Timeout",
"withTimeout(5000) { fetchData() }",
"กำหนด Timeout สำหรับ Network Call",
"ทุก Dispatcher"),
CoroutinePattern("Retry",
"retry(3) { fetchData() } // Custom extension",
"Retry เมื่อ Network Error",
"Dispatchers.IO"),
]
print("=== Coroutine Patterns ===")
for p in patterns:
print(f" [{p.pattern}] {p.code}")
print(f" Use: {p.use_case}")
print(f" Dispatcher: {p.dispatcher}")
Career Roadmap
# === Freelance Career Roadmap ===
@dataclass
class CareerStage:
stage: str
duration: str
skills: str
pricing: str
actions: str
stages = [
CareerStage("1. Learning (0-3 เดือน)",
"3 เดือน",
"Kotlin Coroutines Android Basics Jetpack Compose",
"ยังไม่รับงาน (เตรียมตัว)",
"เรียน Kotlin Docs สร้าง 3 แอป GitHub Blog"),
CareerStage("2. Junior Freelance (3-12 เดือน)",
"9 เดือน",
"Android MVVM Room Retrofit Coroutines Flow",
"$15-30/ชม. (500-1,000 บาท)",
"สมัคร Upwork รับงานเล็ก สะสม Review 5-star"),
CareerStage("3. Mid Freelance (1-3 ปี)",
"2 ปี",
"Clean Architecture Ktor Backend Testing CI/CD",
"$40-80/ชม. (1,200-2,400 บาท)",
"รับงาน Complex App มี Client ประจำ"),
CareerStage("4. Senior Expert (3+ ปี)",
"ต่อเนื่อง",
"Full-stack Kotlin KMP Consulting Architecture",
"$100-200/ชม. (3,000-6,000 บาท)",
"Consulting Speaking Open Source Top-rated"),
]
print("=== Career Roadmap ===")
for s in stages:
print(f"\n [{s.stage}] Duration: {s.duration}")
print(f" Skills: {s.skills}")
print(f" Pricing: {s.pricing}")
print(f" Actions: {s.actions}")
Portfolio Projects
# === Portfolio Project Ideas ===
@dataclass
class Project:
name: str
tech_stack: str
demonstrates: str
complexity: str
projects = [
Project("News Reader App",
"Kotlin + Jetpack Compose + Coroutines + Retrofit + Room + MVVM",
"Network Caching Offline-first Clean Architecture",
"Medium (เหมาะเริ่มต้น)"),
Project("Chat Application",
"Kotlin + Ktor WebSocket + Coroutines Flow + Compose + Firebase",
"Realtime Communication WebSocket Flow Collection",
"High (แสดง Realtime Skill)"),
Project("E-commerce App",
"Kotlin + Compose + Coroutines + Payment API + Clean Architecture",
"Complex Business Logic Payment Cart Order Tracking",
"High (แสดง Full Feature)"),
Project("Weather Dashboard",
"Kotlin + Compose + Coroutines Flow + Location + Charts",
"API Integration Location Reactive UI Data Visualization",
"Medium (UI Skill)"),
Project("REST API Backend",
"Ktor + Coroutines + Exposed DB + JWT Auth + Docker",
"Server-side Kotlin Database Authentication Deployment",
"Medium-High (Full-stack)"),
]
print("=== Portfolio Projects ===")
for p in projects:
print(f" [{p.name}] Complexity: {p.complexity}")
print(f" Stack: {p.tech_stack}")
print(f" Shows: {p.demonstrates}")
เคล็ดลับ
- viewModelScope: ใช้ viewModelScope ใน Android ป้องกัน Memory Leak
- Flow: ใช้ Flow แทน LiveData สำหรับ Reactive Stream
- Dispatchers.IO: ใช้ IO สำหรับ Network/DB ไม่ใช้ Main
- Play Store: เผยแพร่แอปบน Play Store เพิ่ม Portfolio
- Blog: เขียน Kotlin Tips สม่ำเสมอ สร้าง Authority
Kotlin Coroutines คืออะไร
Async Framework suspend launch async Flow Dispatcher Non-blocking Lightweight Structured Concurrency Android Ktor Spring Boot
Async Programming ทำอย่างไร
suspend fun launch async await Flow collect Dispatchers IO Main Default withContext withTimeout try catch Error Handling
Freelance Career Path เป็นอย่างไร
Junior $15-30/ชม. Mid $40-80/ชม. Senior $100-200/ชม. Upwork Toptal Fastwork Android Ktor Portfolio Review Blog
Portfolio สร้างอย่างไร
News Chat E-commerce Weather API Backend Compose Coroutines MVVM Clean Architecture GitHub Play Store Blog Dev.to
สรุป
Kotlin Coroutines Freelance IT Career suspend async Flow Android Ktor MVVM Clean Architecture Portfolio Upwork Pricing Blog
