Skip to content

Conversation

@LouisCAD
Copy link
Contributor

Add contract to CoroutineDispatcher.invoke operator, to allow initializing read-only properties declared before, from inside the passed block.

https://youtrack.jetbrains.com/issue/KT-32313/Support-contracts-for-operator-functions

This commit also improve the KDoc to show a usage example, and explain why it's less error-prone than withContext.

Add contract to CoroutineDispatcher.invoke operator,
to allow initializing read-only properties declared before,
from inside the passed block.

https://youtrack.jetbrains.com/issue/KT-32313/Support-contracts-for-operator-functions

This commit also improve the KDoc to show a usage example,
and explain why it's less error-prone than withContext.
@qwwdfsad qwwdfsad self-requested a review November 7, 2025 18:16
Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

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

Thanks! Could you please also add a test for that? (i.e. like RunBlocking.testContract)

*
* Example usage:
* ```
* Dispatchers.IO { someFile.exists() } // Checking the file system is blocking I/O.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Dispatchers.IO { someFile.exists() } // Checking the file system is blocking I/O.
* Dispatchers.IO {
* someFile.exists() // Checking the file system is blocking I/O
* }

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