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;








-2















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










share|improve this question






















  • 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

















-2















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










share|improve this question






















  • 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













-2












-2








-2








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















4














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.






share|improve this answer

























  • 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











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
);



);













draft saved

draft discarded


















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









4














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.






share|improve this answer

























  • 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















4














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.






share|improve this answer

























  • 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













4












4








4







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.






share|improve this answer















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.







share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현