๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿค2024 ์•ˆ๋“œ๋กœ์ด๋“œ/โ˜€๏ธ ํ•˜๊ณ„ ์ธํ„ด ๊ฐœ๋ฐœ ํ”„๋กœ์ ํŠธ ๊ธฐ๋ก

lifecycleScope.launch๋Š” ๋ฉ”์ธ ์Šค๋ ˆ๋“œ์—์„œ๋งŒ ๋Œ์•„๊ฐˆ๊นŒ?

by hyeonha 2024. 9. 10.

๋ชฉ์ฐจ

    lifecyclerScope.launch๋ฅผ IO ์Šค๋ ˆ๋“œ์—์„œ ์‚ฌ์šฉํ•˜๊ธฐ

    ์˜ค๋Š˜ ๊ฐœ๋ฐœ์„ ํ•˜๋‹ค๊ฐ€ ์ฒ˜์Œ ์•ˆ ์‚ฌ์‹ค์„ ๊ณต์œ ํ•ด๋ณด๋ ค ํ•œ๋‹ค.

     

    ๋‚˜๋Š” ๊ทธ๋™์•ˆ ์•กํ‹ฐ๋น„ํ‹ฐ๋‚˜ ํ”„๋ž˜๊ทธ๋จผํŠธ์—์„œ ๋น„๋™๊ธฐ๋ฅผ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด lifecycleScope.launch๋ฅผ ์‚ฌ์šฉํ•ด์™”๋‹ค.

    lifecycleScope.launch { }

     

    ๊ทธ๋ฆฌ๊ณ  ์ถ”๊ฐ€๋กœ IO ์Šค๋ ˆ๋“œ๋‚˜ Default , Main์œผ๋กœ์˜ ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•  ๋•Œ๋Š” CoroutineScope๋ฅผ ์‚ฌ์šฉํ•ด์ฃผ์—ˆ๋Š”๋ฐ ... ! 

    CoroutineScope(Dispatchers.IO).launch { }

     

     

     

    ์ด๋ ‡๊ฒŒ๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ–ˆ๋˜ ๊ฒƒ์ด๋‹ค!!!!! 

    lifecycleScope.launch(Dispatchers.IO) {
    

     

    ์ด๋ฅผ ํ†ตํ•ด ์•กํ‹ฐ๋น„ํ‹ฐ๋‚˜ ํ”„๋ž˜๊ทธ๋จผํŠธ์˜ ์ƒ๋ช… ์ฃผ๊ธฐ๋ฅผ ๋”ฐ๋ฅด๋ฉด์„œ IO ์Šค๋ ˆ๋“œ์—์„œ ์ˆ˜ํ–‰ํ•˜๊ณ  ์‹ถ์€ ์ž‘์—…์„ ์Šค๋ ˆ๋“œ์—์„œ ์‹คํ–‰ํ•ด์ค„ ์ˆ˜ ์žˆ๋‹ค.

    728x90