Questions tagged [suspend]
469 questions
7
votes
2 answers
how does suspend function not block the main thread?
A coroutine started on Dispatchers.Main won't block the main thread while suspended.
what does this mean?
so when suspend function started on main thread when has some lines which takes longer, does it automatically assign to new thread?
this is…

Vikas Pandey
- 1,115
- 1
- 15
- 25
7
votes
1 answer
Access UI thread while app is being suspended?
I have a UWP app that lets users create and modify text documents. I'm having a hard time getting the save mechanism to work with the app suspend/resume lifecycle.
Here is what I have:
All disk access is done on a separate background thread to keep…

Mark
- 6,647
- 1
- 45
- 88
7
votes
3 answers
waking up from pm-suspend results in full restart
Waking up from
$ sudo pm-suspend
results in anomalous behaviour depending on whether the laptop in connected to external power.
The following scenarios have been tested to be reproducible:
Suspend while on AC power, wake up. Result: normal…

Kaveh Gharavi
- 87
- 1
- 6
7
votes
0 answers
Sleep-defiant timer, ideally Reactive
The following code ticks nicely every two minutes under normal conditions:
Observable.Interval(TimeSpan.FromSeconds(120)).Subscribe(
l =>
{
var now = DateTime.Now;
Console.WriteLine(
…

Cel
- 6,467
- 8
- 75
- 110
7
votes
1 answer
After pm-suspend computer immediately wakes up. How to determine what caused it?
I am running a Debian-Jessy Server, that goes into S3 sleep mode after some hours network inactivity (I made a small bash script that checks it every two hours with crontab). Several seconds after suspending, it wakes up again. After a few hours,…

Holger S.
- 71
- 1
- 4
7
votes
1 answer
How to get thread state (e.g. suspended), memory + CPU usage, start time, priority, etc
How do I get the information if a thread has been suspended with SuspendThread(). There is no API that gives this information. The toolhelp snapshot API is very limited.
There is a lot of misleading information in internet and also on StackOverflow.…

Elmue
- 7,602
- 3
- 47
- 57
6
votes
2 answers
When to use suspend function and Flow together or seperate in kotlin?
While reviewing some code written in kotlin ,something caught my attention. I was looking about domain layer in some projects and in some of the projects, I saw that the suspend function and Flow were used together, and in some of the projects, I…

NewPartizal
- 604
- 4
- 18
6
votes
6 answers
Sleep / Suspend / Hibernate Windows PC
I'd like to write a short python script that puts my computer to sleep. I'Ve already searched the API but the only result on suspend has to do with delayed execution. What function does the trick ?

lhk
- 27,458
- 30
- 122
- 201
6
votes
0 answers
Android Studio and Kotlin - Set breakpoint at runtime in a suspend function doesn't work
In my Android app developed in Kotlin I'm not able to make the debugger stop on breakpoints set at runtime in a Dynamic Feature with suspend functions. If I set the breakpoint before launching the app it works, but when I try to set the same…

Sergiob
- 838
- 1
- 13
- 28
6
votes
2 answers
Android instrumented test freezes when it tests a suspend function that uses RoomDatabase.withTransaction
I'm trying to test the following LocalDataSource function, NameLocalData.methodThatFreezes function, but it freezes. How can I solve this? Or How can I test it in another way?
Class to be tested
class NameLocalData(private val roomDatabase:…

heronsanches
- 524
- 7
- 12
6
votes
1 answer
'Overload resolution ambiguity' with and without 'suspend' lambda in functions
Look at this example:
fun f(block: suspend () -> Unit) {
println("with suspend")
}
fun f(block: () -> Unit) {
println("without suspend")
}
fun main() {
f(suspend {
})
// This call cause compilation error:
// Error:(16, 5)…

Maxim
- 9,701
- 5
- 60
- 108
6
votes
1 answer
Kotlin suspend modifier changes function signature, but compiler reports overload error
Introduction
Given two functions, foo() and foo(), the first one is standard and the second is suspendible
fun foo(x: Int): Int {
return 2*x
}
suspend fun foo(x: Int): Int {
return 4*x
}
The following code does not compile, because two…

ci0ccarellia
- 795
- 9
- 26
6
votes
1 answer
Kotlin foreach on a map vs iterating over the keys when used with coroutines
I'm confused about what is going on with the following code. task.yield is a hashmap from a to b, and store.put is a suspend function which takes an a and a b. The first way of iterating thru the map works with no issue, as does the second. The…

htuy42
- 307
- 3
- 10
6
votes
1 answer
Migrate callback code to suspended function
I'm re-factoring my Android code from Java to Kotlin using coroutines but i did not find an easy way to rewrite callback-based code to suspended functions.
A basic example would be an alert popup that returns a result, in Javascript it would be…

Plokko
- 723
- 2
- 10
- 23
6
votes
2 answers
How to pause program execution in Pycharm (pause button not working)?
While debugging my Python 3.5 pogram in Pycharm 5.0.4, I am trying to hit the pause button to find how why/where the program is hanging (as can be done in Visual Studio).
However, nothing happens: the pause button does not become grey and the resume…

Erwin Mayer
- 18,076
- 9
- 88
- 126