Is delay() In Kotlin Coroutine a non-blocking function?What is non-blocking or asynchronous I/O in Node.js?What is the equivalent of Java static methods in Kotlin?Difference between thread and coroutine in KotlinWhat is the difference between launch/join and async/await in Kotlin coroutinesCan “experimental” Kotlin coroutines be used in production?What does suspend function mean in Kotlin Coroutinekotlin coroutines - use main thread in run blockingKotlin coroutine async with delayWhen should I make my normal function suspending function?How to achieve non blocking with CoroutinesBasic coroutine network call in a library
Meaning of 'lose their grip on the groins of their followers'
Can I utilise a baking stone to make crepes?
How to communicate to my GM that not being allowed to use stealth isn't fun for me?
Why does the Mishnah use the terms poor person and homeowner when discussing carrying on Shabbat?
Active low-pass filters --- good to what frequencies?
Are polynomials with the same roots identical?
Overlapping String-Blocks
Finding value of expression with roots of a given polynomial.
Are there any important biographies of nobodies?
Is an entry level DSLR going to shoot nice portrait pictures?
How come the nude protesters were not arrested?
Cascading Switches. Will it affect performance?
LuaLaTex - how to use number, computed later in the document
Bb13b9 confusion
Why not invest in precious metals?
Is using 'echo' to display attacker-controlled data on the terminal dangerous?
How does the Around command at zero work?
US doctor working in Tripoli wants me to open online account
English word for "product of tinkering"
Why was this person allowed to become Grand Maester?
Extreme flexible working hours: how to get to know people and activities?
Is it expected that a reader will skip parts of what you write?
Why are trash cans referred to as "zafacón" in Puerto Rico?
How to hide rifle during medieval town entrance inspection?
Is delay() In Kotlin Coroutine a non-blocking function?
What is non-blocking or asynchronous I/O in Node.js?What is the equivalent of Java static methods in Kotlin?Difference between thread and coroutine in KotlinWhat is the difference between launch/join and async/await in Kotlin coroutinesCan “experimental” Kotlin coroutines be used in production?What does suspend function mean in Kotlin Coroutinekotlin coroutines - use main thread in run blockingKotlin coroutine async with delayWhen should I make my normal function suspending function?How to achieve non blocking with CoroutinesBasic coroutine network call in a library
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
The comment in example code says delay() is non-blocking. Should it be suspending ?
https://kotlinlang.org/docs/reference/coroutines/basics.html
fun main()
GlobalScope.launch // launch new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
println("Hello,") // main thread continues while coroutine is delayed
Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive
kotlin kotlin-coroutines
|
show 1 more comment
The comment in example code says delay() is non-blocking. Should it be suspending ?
https://kotlinlang.org/docs/reference/coroutines/basics.html
fun main()
GlobalScope.launch // launch new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
println("Hello,") // main thread continues while coroutine is delayed
Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive
kotlin kotlin-coroutines
It is a correct description because it does not block any thread, it just suspends the current coroutine.
– Moira
Mar 24 at 19:15
non-blocking is a well defined term in Computer Science. The println("World!") would be run immediately, instead of waiting for 1 second, based on the definition. Don't use this term if your meaning is different.
– user1443721
Mar 25 at 4:32
My meaning is definitely not different, I don't see what you're trying to say. Delay is not a blocking call, as I just explained.
– Moira
Mar 25 at 5:32
@Moira: delay is suspending and non-blocking. Joffrey has answered it. it is not "non-blocking" only.
– user1443721
Mar 25 at 23:05
@Moira: as you said, "it just suspends the current coroutine". Why does the comment for the delay call not say so? Instead, the comment is "non-blocking". Is it not misleading?
– user1443721
Mar 26 at 4:34
|
show 1 more comment
The comment in example code says delay() is non-blocking. Should it be suspending ?
https://kotlinlang.org/docs/reference/coroutines/basics.html
fun main()
GlobalScope.launch // launch new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
println("Hello,") // main thread continues while coroutine is delayed
Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive
kotlin kotlin-coroutines
The comment in example code says delay() is non-blocking. Should it be suspending ?
https://kotlinlang.org/docs/reference/coroutines/basics.html
fun main()
GlobalScope.launch // launch new coroutine in background and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
println("Hello,") // main thread continues while coroutine is delayed
Thread.sleep(2000L) // block main thread for 2 seconds to keep JVM alive
kotlin kotlin-coroutines
kotlin kotlin-coroutines
asked Mar 24 at 18:57
user1443721user1443721
2141518
2141518
It is a correct description because it does not block any thread, it just suspends the current coroutine.
– Moira
Mar 24 at 19:15
non-blocking is a well defined term in Computer Science. The println("World!") would be run immediately, instead of waiting for 1 second, based on the definition. Don't use this term if your meaning is different.
– user1443721
Mar 25 at 4:32
My meaning is definitely not different, I don't see what you're trying to say. Delay is not a blocking call, as I just explained.
– Moira
Mar 25 at 5:32
@Moira: delay is suspending and non-blocking. Joffrey has answered it. it is not "non-blocking" only.
– user1443721
Mar 25 at 23:05
@Moira: as you said, "it just suspends the current coroutine". Why does the comment for the delay call not say so? Instead, the comment is "non-blocking". Is it not misleading?
– user1443721
Mar 26 at 4:34
|
show 1 more comment
It is a correct description because it does not block any thread, it just suspends the current coroutine.
– Moira
Mar 24 at 19:15
non-blocking is a well defined term in Computer Science. The println("World!") would be run immediately, instead of waiting for 1 second, based on the definition. Don't use this term if your meaning is different.
– user1443721
Mar 25 at 4:32
My meaning is definitely not different, I don't see what you're trying to say. Delay is not a blocking call, as I just explained.
– Moira
Mar 25 at 5:32
@Moira: delay is suspending and non-blocking. Joffrey has answered it. it is not "non-blocking" only.
– user1443721
Mar 25 at 23:05
@Moira: as you said, "it just suspends the current coroutine". Why does the comment for the delay call not say so? Instead, the comment is "non-blocking". Is it not misleading?
– user1443721
Mar 26 at 4:34
It is a correct description because it does not block any thread, it just suspends the current coroutine.
– Moira
Mar 24 at 19:15
It is a correct description because it does not block any thread, it just suspends the current coroutine.
– Moira
Mar 24 at 19:15
non-blocking is a well defined term in Computer Science. The println("World!") would be run immediately, instead of waiting for 1 second, based on the definition. Don't use this term if your meaning is different.
– user1443721
Mar 25 at 4:32
non-blocking is a well defined term in Computer Science. The println("World!") would be run immediately, instead of waiting for 1 second, based on the definition. Don't use this term if your meaning is different.
– user1443721
Mar 25 at 4:32
My meaning is definitely not different, I don't see what you're trying to say. Delay is not a blocking call, as I just explained.
– Moira
Mar 25 at 5:32
My meaning is definitely not different, I don't see what you're trying to say. Delay is not a blocking call, as I just explained.
– Moira
Mar 25 at 5:32
@Moira: delay is suspending and non-blocking. Joffrey has answered it. it is not "non-blocking" only.
– user1443721
Mar 25 at 23:05
@Moira: delay is suspending and non-blocking. Joffrey has answered it. it is not "non-blocking" only.
– user1443721
Mar 25 at 23:05
@Moira: as you said, "it just suspends the current coroutine". Why does the comment for the delay call not say so? Instead, the comment is "non-blocking". Is it not misleading?
– user1443721
Mar 26 at 4:34
@Moira: as you said, "it just suspends the current coroutine". Why does the comment for the delay call not say so? Instead, the comment is "non-blocking". Is it not misleading?
– user1443721
Mar 26 at 4:34
|
show 1 more comment
1 Answer
1
active
oldest
votes
The Kotlin documentation often says "non-blocking" for suspending functions to make it clear that they don't block the current thread, but simply suspend the current coroutine.
So yes, delay
is suspending and non-blocking.
It may be misleading sometimes because "non-blocking" places the emphasis on the fact that nothing is blocked, while it should still be made clear that suspending functions do suspend the current coroutine (so at least something is kinda blocked, even if the thread itself carries on).
The fact that they suspend the current coroutine make these functions appear synchronous from the point of view of the current coroutine, because the coroutine needs to wait for these functions to complete before executing the rest of the code. However, they don't actually block the current thread because their implementation uses asynchronous mechanisms under the cover.
Thanks! Your answer is reasonable. "non-blocking" here is really misleading. The formal document should not use this well defined term for something else. Coroutine is a new feature. It is worth to define a new set of terms to explain the features.
– user1443721
Mar 25 at 4:41
@user1443721 FWIW this terminology is not new to asynchronous programming at all; see the C# docs for example.
– Moira
Mar 25 at 6:31
1
@user1443721 That's exactly what Kotiln did. The new terminology is "suspending" while the old terminology ("blocking") keeps the old meaning and still refers to threads.
– Marko Topolnik
Mar 25 at 7:37
@Moira: non-blocking has been well defined, even earlier than C#. check the answer to this question, stackoverflow.com/questions/10570246/…
– user1443721
Mar 26 at 3:32
@Marko Topolnik: "suspending" is not new terminology. It has been used to describe thread life cycle. My question is mainly on the comment for delay() function in the example.
– user1443721
Mar 26 at 4:29
|
show 8 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327378%2fis-delay-in-kotlin-coroutine-a-non-blocking-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Kotlin documentation often says "non-blocking" for suspending functions to make it clear that they don't block the current thread, but simply suspend the current coroutine.
So yes, delay
is suspending and non-blocking.
It may be misleading sometimes because "non-blocking" places the emphasis on the fact that nothing is blocked, while it should still be made clear that suspending functions do suspend the current coroutine (so at least something is kinda blocked, even if the thread itself carries on).
The fact that they suspend the current coroutine make these functions appear synchronous from the point of view of the current coroutine, because the coroutine needs to wait for these functions to complete before executing the rest of the code. However, they don't actually block the current thread because their implementation uses asynchronous mechanisms under the cover.
Thanks! Your answer is reasonable. "non-blocking" here is really misleading. The formal document should not use this well defined term for something else. Coroutine is a new feature. It is worth to define a new set of terms to explain the features.
– user1443721
Mar 25 at 4:41
@user1443721 FWIW this terminology is not new to asynchronous programming at all; see the C# docs for example.
– Moira
Mar 25 at 6:31
1
@user1443721 That's exactly what Kotiln did. The new terminology is "suspending" while the old terminology ("blocking") keeps the old meaning and still refers to threads.
– Marko Topolnik
Mar 25 at 7:37
@Moira: non-blocking has been well defined, even earlier than C#. check the answer to this question, stackoverflow.com/questions/10570246/…
– user1443721
Mar 26 at 3:32
@Marko Topolnik: "suspending" is not new terminology. It has been used to describe thread life cycle. My question is mainly on the comment for delay() function in the example.
– user1443721
Mar 26 at 4:29
|
show 8 more comments
The Kotlin documentation often says "non-blocking" for suspending functions to make it clear that they don't block the current thread, but simply suspend the current coroutine.
So yes, delay
is suspending and non-blocking.
It may be misleading sometimes because "non-blocking" places the emphasis on the fact that nothing is blocked, while it should still be made clear that suspending functions do suspend the current coroutine (so at least something is kinda blocked, even if the thread itself carries on).
The fact that they suspend the current coroutine make these functions appear synchronous from the point of view of the current coroutine, because the coroutine needs to wait for these functions to complete before executing the rest of the code. However, they don't actually block the current thread because their implementation uses asynchronous mechanisms under the cover.
Thanks! Your answer is reasonable. "non-blocking" here is really misleading. The formal document should not use this well defined term for something else. Coroutine is a new feature. It is worth to define a new set of terms to explain the features.
– user1443721
Mar 25 at 4:41
@user1443721 FWIW this terminology is not new to asynchronous programming at all; see the C# docs for example.
– Moira
Mar 25 at 6:31
1
@user1443721 That's exactly what Kotiln did. The new terminology is "suspending" while the old terminology ("blocking") keeps the old meaning and still refers to threads.
– Marko Topolnik
Mar 25 at 7:37
@Moira: non-blocking has been well defined, even earlier than C#. check the answer to this question, stackoverflow.com/questions/10570246/…
– user1443721
Mar 26 at 3:32
@Marko Topolnik: "suspending" is not new terminology. It has been used to describe thread life cycle. My question is mainly on the comment for delay() function in the example.
– user1443721
Mar 26 at 4:29
|
show 8 more comments
The Kotlin documentation often says "non-blocking" for suspending functions to make it clear that they don't block the current thread, but simply suspend the current coroutine.
So yes, delay
is suspending and non-blocking.
It may be misleading sometimes because "non-blocking" places the emphasis on the fact that nothing is blocked, while it should still be made clear that suspending functions do suspend the current coroutine (so at least something is kinda blocked, even if the thread itself carries on).
The fact that they suspend the current coroutine make these functions appear synchronous from the point of view of the current coroutine, because the coroutine needs to wait for these functions to complete before executing the rest of the code. However, they don't actually block the current thread because their implementation uses asynchronous mechanisms under the cover.
The Kotlin documentation often says "non-blocking" for suspending functions to make it clear that they don't block the current thread, but simply suspend the current coroutine.
So yes, delay
is suspending and non-blocking.
It may be misleading sometimes because "non-blocking" places the emphasis on the fact that nothing is blocked, while it should still be made clear that suspending functions do suspend the current coroutine (so at least something is kinda blocked, even if the thread itself carries on).
The fact that they suspend the current coroutine make these functions appear synchronous from the point of view of the current coroutine, because the coroutine needs to wait for these functions to complete before executing the rest of the code. However, they don't actually block the current thread because their implementation uses asynchronous mechanisms under the cover.
edited Mar 24 at 19:29
answered Mar 24 at 19:24
JoffreyJoffrey
7,73312953
7,73312953
Thanks! Your answer is reasonable. "non-blocking" here is really misleading. The formal document should not use this well defined term for something else. Coroutine is a new feature. It is worth to define a new set of terms to explain the features.
– user1443721
Mar 25 at 4:41
@user1443721 FWIW this terminology is not new to asynchronous programming at all; see the C# docs for example.
– Moira
Mar 25 at 6:31
1
@user1443721 That's exactly what Kotiln did. The new terminology is "suspending" while the old terminology ("blocking") keeps the old meaning and still refers to threads.
– Marko Topolnik
Mar 25 at 7:37
@Moira: non-blocking has been well defined, even earlier than C#. check the answer to this question, stackoverflow.com/questions/10570246/…
– user1443721
Mar 26 at 3:32
@Marko Topolnik: "suspending" is not new terminology. It has been used to describe thread life cycle. My question is mainly on the comment for delay() function in the example.
– user1443721
Mar 26 at 4:29
|
show 8 more comments
Thanks! Your answer is reasonable. "non-blocking" here is really misleading. The formal document should not use this well defined term for something else. Coroutine is a new feature. It is worth to define a new set of terms to explain the features.
– user1443721
Mar 25 at 4:41
@user1443721 FWIW this terminology is not new to asynchronous programming at all; see the C# docs for example.
– Moira
Mar 25 at 6:31
1
@user1443721 That's exactly what Kotiln did. The new terminology is "suspending" while the old terminology ("blocking") keeps the old meaning and still refers to threads.
– Marko Topolnik
Mar 25 at 7:37
@Moira: non-blocking has been well defined, even earlier than C#. check the answer to this question, stackoverflow.com/questions/10570246/…
– user1443721
Mar 26 at 3:32
@Marko Topolnik: "suspending" is not new terminology. It has been used to describe thread life cycle. My question is mainly on the comment for delay() function in the example.
– user1443721
Mar 26 at 4:29
Thanks! Your answer is reasonable. "non-blocking" here is really misleading. The formal document should not use this well defined term for something else. Coroutine is a new feature. It is worth to define a new set of terms to explain the features.
– user1443721
Mar 25 at 4:41
Thanks! Your answer is reasonable. "non-blocking" here is really misleading. The formal document should not use this well defined term for something else. Coroutine is a new feature. It is worth to define a new set of terms to explain the features.
– user1443721
Mar 25 at 4:41
@user1443721 FWIW this terminology is not new to asynchronous programming at all; see the C# docs for example.
– Moira
Mar 25 at 6:31
@user1443721 FWIW this terminology is not new to asynchronous programming at all; see the C# docs for example.
– Moira
Mar 25 at 6:31
1
1
@user1443721 That's exactly what Kotiln did. The new terminology is "suspending" while the old terminology ("blocking") keeps the old meaning and still refers to threads.
– Marko Topolnik
Mar 25 at 7:37
@user1443721 That's exactly what Kotiln did. The new terminology is "suspending" while the old terminology ("blocking") keeps the old meaning and still refers to threads.
– Marko Topolnik
Mar 25 at 7:37
@Moira: non-blocking has been well defined, even earlier than C#. check the answer to this question, stackoverflow.com/questions/10570246/…
– user1443721
Mar 26 at 3:32
@Moira: non-blocking has been well defined, even earlier than C#. check the answer to this question, stackoverflow.com/questions/10570246/…
– user1443721
Mar 26 at 3:32
@Marko Topolnik: "suspending" is not new terminology. It has been used to describe thread life cycle. My question is mainly on the comment for delay() function in the example.
– user1443721
Mar 26 at 4:29
@Marko Topolnik: "suspending" is not new terminology. It has been used to describe thread life cycle. My question is mainly on the comment for delay() function in the example.
– user1443721
Mar 26 at 4:29
|
show 8 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55327378%2fis-delay-in-kotlin-coroutine-a-non-blocking-function%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It is a correct description because it does not block any thread, it just suspends the current coroutine.
– Moira
Mar 24 at 19:15
non-blocking is a well defined term in Computer Science. The println("World!") would be run immediately, instead of waiting for 1 second, based on the definition. Don't use this term if your meaning is different.
– user1443721
Mar 25 at 4:32
My meaning is definitely not different, I don't see what you're trying to say. Delay is not a blocking call, as I just explained.
– Moira
Mar 25 at 5:32
@Moira: delay is suspending and non-blocking. Joffrey has answered it. it is not "non-blocking" only.
– user1443721
Mar 25 at 23:05
@Moira: as you said, "it just suspends the current coroutine". Why does the comment for the delay call not say so? Instead, the comment is "non-blocking". Is it not misleading?
– user1443721
Mar 26 at 4:34