Skip to content

Hw 10 coroutines#10

Open
Karakurik wants to merge 4 commits intomasterfrom
hw-10-coroutines
Open

Hw 10 coroutines#10
Karakurik wants to merge 4 commits intomasterfrom
hw-10-coroutines

Conversation

@Karakurik
Copy link
Copy Markdown
Owner

No description provided.

AppDatabase::class.java,
"app-db"
).run {
allowMainThreadQueries()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для корутин можно было уже убрать

database = Room.databaseBuilder(
applicationContext,
AppDatabase::class.java,
"app-db"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше добавить расширение .db, и вынести в константу

override fun onCreate() {
super.onCreate()
instance = this
database = Room.databaseBuilder(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше код создание бд оставить внутри класса AppDatabase, чтобы потом можно было в другом месте переиспользовать при необходисомти

override fun submitList(list: MutableList<Task>?) {
super.submitList(
if (list == null) null
else ArrayList(list)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

перенос строки тут не нужен


private suspend fun setTaskEditingView(id: Int) {
val task = scope.async {
withContext(Dispatchers.IO) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в данном случае ты мог написать scope.async(Dispatchers.IO) {}

но а так для рума и в этом нужды нет, под коробкой он генерит код с withContext(IO)

database?.taskDao()?.findById(id)
}
}.await()
binding?.apply {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cемантически здесь будет верно run

calendar?.also {
task.date = it.time
}
scope.launch {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично, мог сразу launch(io) написать

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants