Questions tagged [coroutine]

Coroutines are a general control structure whereby flow control is cooperatively passed between two different routines without returning.

1
vote
1answer
28 views

How to use Kotlinc coroutine in non android project?

I am new to Kotlin and trying to learn asynchronous programming using coroutine. I am following Kotlin official docs. But when I tried to compile my code, it showed me error: "unresolved reference: ...
0
votes
1answer
19 views

How to prevent the usage of try catch with suspendCancellableCoroutine

I have made a corouting that calls an asynchronous method in my interactor, the thing is that when the continuation block gets executed, I dont want to use a try catch block since I think is not the ...
1
vote
2answers
43 views

How to return error responses from Coroutines

I'm trying to change all my callbacks to coroutines, I have readed about them and they are fasinating ! What I want to accomplish is just login a user, but if the login logic fails, notify it to my ...
5
votes
1answer
62 views

Who is responsible for suspension and continuation of coroutines?

This might be a very basic question in terms of Asynchronous Programming, but I tried reading about it but couldn't find any resource for the same. Assumption: In general about asynchronous ...
2
votes
1answer
42 views

How can I pause spawning in a coroutine until all the spawned objects are destroyed?

I just don't know how to write the if part. The rest is just instantiate position and quaternion stuff.... Probably. I want to know if the GameObject rocketspawnblue and GameObject rocketspawnred ...
0
votes
1answer
35 views

produce<Type> vs Channel<Type>()

Trying to understand channels. I want to channelify the android BluetoothLeScanner. Why does this work: fun startScan(filters: List<ScanFilter>, settings: ScanSettings = defaultSettings): ...
3
votes
1answer
75 views

What causes this code `Segmentation fault` after a coroutine call `promise_type::return_value()`?

Updated The Segmentation fault was caused by trying .get() on an invalid std::future. However the coroutines still don't quite work yet. [godbolt] [wandbox] I have awaitable type like this : ...
3
votes
2answers
70 views

When will/won't Python suspend execution of a coroutine?

When I run it on cpython 3.6, the following program prints hello world a single time and then spins forever. As a side note, uncommenting the await asyncio.sleep(0) line causes it to print hello ...
0
votes
0answers
19 views

how to repeat/execute a coroutine at the same time using asyncio.gather?

I've tried to run a coroutine twice at the same time(below) but I got a RuntimeError: This event loop is already running. unfortunately I fund noting helpful from google. I appreciate your help in ...
1
vote
1answer
47 views

Kotlin Coroutines suspend fun + retrofit throws “No Retrofit annotation found” error

I'm trying to use retrofit's coroutine support in 2.5.1-SNAPSHOT but I keep getting a strange exception. My retrofit service class has: @GET("weather") suspend fun getForecast(@Query("q") query: ...
1
vote
1answer
74 views

How to overwrite the return address of the assembler stack with an address given by C++?

I got a function switchContext(void*& from, void*& to). It receives two stack pointers and shall change the context of a process. So if I got a coroutine A and it uses a specific function ...
1
vote
1answer
33 views

Panel should fade in then a new scene should load in

When a trigger is activated a panel should fade in then a new scene should load. Unfortunately only one of these things happens. I would like one to happen after the other. public void transitionpef(...
1
vote
1answer
29 views

Unit Testing CoroutineExceptionHandler

Hello I have this code that uses coroutines and I want to unit test it : My problem is that my exception is never catched by the CoroutineExceptionHandler. My code looks something like the following ...
2
votes
0answers
40 views

Kotlin coroutines & JavaMail blocking IO

I'm experimenting with Kotlin coroutines to write a high performance IMAP client interacting with potentially 1,000's of mail boxes at the same time. I'm using JavaMail to do the IMAP protocol work ...
0
votes
1answer
26 views

How to deal with exception with Deferred await error in Retrofit

Our application has many network requests and we are using Coroutines with Retrofit like this: suspend fun fetchAccountInfo() { val api = retrofit.create(MainActivityApi::class.java) val ...
0
votes
1answer
23 views

Coroutines with LiveData

Get compilation error when try to run the below code : The code success fully run if i changed the return type to List, but i wanted to return the live data object from the suspended function. @Dao ...
1
vote
1answer
71 views

Player don't move slowly ( smoothly)

I have a question please in my game when i write "LEFT" in a InputField and click on a UI Button the cube move "LEFT" and eat coins(the same for up, down , right) my problem is when i wrote this code ...
8
votes
1answer
134 views

Python coroutines: Release context manager when pausing

Background: I'm a very experienced Python programmer who is completely clueless about the new coroutines/async/await features. I can't write an async "hello world" to save my life. My question is: I ...
0
votes
0answers
36 views

The example of the coroutine from documentation does not work

I started to learn coroutine and have tried run the code from example structured-concurrency. But I got another result. If set delay(1000L) "Hellow, " only was printed and Process finished with exit ...
0
votes
1answer
45 views

Coroutines: Is there a way to block multiple executions and notify them all?

I've been trying to implement a wait & notifyAll system like I used to do in Java. Main idea is to make multiple functions call to wait for a signal and continue their execution. The following ...
0
votes
0answers
42 views

Android Shared Preference using Kotlin with support for LiveData and Coroutines Library

I wrote a small helper library for accessing shared preference values in Kotlin Andorid. It's my first library and my first time using Kotlin. Happy for any feedback :) Available on Github: https://...
0
votes
1answer
25 views

Using coroutines to fade in/out TextMeshPro Text Element

I am setting up a "scene intro" with some text saying 'Level 1' using TextMeshPro. I have created the text element in canvas and i am trying to find a way to make it fade in, then wait, and then fade ...
0
votes
1answer
34 views

Adding Game Objects to list forever problem

I have a prefab that I am adding to a list with timing in between for game functionality. However it never stops adding Game Objects. In the addToPath() the for loop right there spawns 1 object every ...
0
votes
1answer
28 views

Unity, Coroutine acts different on Android

Next code below acts different on Android, while in Editor it acts as supposed: private IEnumerator CountTo(int target) { yield return new WaitForSeconds(0.5f); int start = 0; do ...
2
votes
0answers
43 views

Why RISCV choose “push and pop” RAS for coroutines?

In riscv-spec-2.2, it provide the following truth table for Return Address Stack (RAS) behavior: rd rs1 rs1=rd RAS action !link !link - none !link link - pop link !link ...
1
vote
1answer
28 views

Proper re-execution of coroutine?

I'm creating a game using lua; I need a timer to run during game intermissions as well as during game rounds. The game initially executes with an intermission of 15 seconds. The timer runs fine in ...
0
votes
0answers
23 views

How do I “filter” the yielded values of a coroutine so they never reach the consumer?

I'm trying to wrap my head around coroutines in PureScript, more specifically I'm now trying to apply a filter of some kind to a producer. Consider the following code, that is just a random number ...
2
votes
2answers
70 views

Why can kotlin coroutines operate UI elements on another thread

I'm trying kotlinx.coroutines (version: 1.2.0). Here is a simple test code block: GlobalScope.launch { Logger.i("${Thread.currentThread()}, ${Looper.myLooper() == Looper.getMainLooper()}") ...
4
votes
1answer
100 views

Hide blocking operation with coroutine

I have a service that receives data via UDP and I'd like to add a few zmq subscribers. I also want to use zmq sockets without blocking. And I don't want to create a separate thread for it. I could ...
0
votes
1answer
80 views

Android Coroutines

I am trying to work through the coroutines code lab from Google: https://codelabs.developers.google.com/codelabs/kotlin-coroutines/#0 When I build the project I get the error: More than one file ...
0
votes
2answers
44 views

Coroutine does no play all the way through

Unfortunately my co routine does not play all the way through. It is supposed to fade an object so it's alpha is 0. However it fades to .039. { StartCoroutine(colorlerpin7()); yield return ...
0
votes
1answer
59 views

How to solve this Coroutine circularly reference error?

I have an exam tomorrow on coroutines, but the problem is that the lecture on that chapter was canceled for the exam and no replacement. So I decided to study coroutines on my own, wich was hard. I ...
0
votes
1answer
83 views

How to handle error response with retrofit + coroutines

I'm new with coroutines. Trying to use retrofit + coroutines + Jake Wharton's CoroutineCallAdapterFactory by this tutorial But don't get how to handle json response errors. For example error could be ...
1
vote
2answers
517 views

sys:1: RuntimeWarning: coroutine was never awaited

I am trying to write a request handler to help me send request in async mode. It prompt when I close the python terminal with Ctrl+D or exit() It shows sys:1: RuntimeWarning: coroutine was never ...
1
vote
1answer
55 views

Understanding coroutine

From wikipedia the paragraph Comparison with threads states: ... This means that coroutines provide concurrency but not parallelism ... I understand that coroutine is lighter than thread, ...
0
votes
0answers
11 views

Android coroutine scope lost if called from a non suspendable block

I'm trying to execute a suspendable function from a lambda expression: fun executeAll() { // non-ui thread required for this task. Retain the jobId and clear it once the VM is destroyed ...
0
votes
0answers
15 views

about libdill, dill_brecv must be in the same dill_coroutine whith dill_tcp_connect?

The test code is below: #include <stdio.h> #include <libdill.h> static dill_coroutine void test_1(void) { int ret; while(dill_msleep(dill_now() + 1000) == 0) { printf("test_1: ...
0
votes
3answers
98 views

LiveData and Coroutines - Property must be initialized or abstract

I am trying to use LiveData and Coroutines together in MVVM, and I may be missing something simple. class WeatherViewModel ( private val weatherRepository: ForecastRepository ) : ViewModel() { ...
0
votes
1answer
32 views

Is libc++ coroutine's suspend_always::await_suspend supposed to be “exported” to c++experimental.lib?

I've got this error when compile coroutine against libc++ that I built "C:\\Program Files\\LLVM\\bin\\lld-link" ... c++.lib c++experimental.lib ... lld-link: error: undefined symbol: __declspec(...
2
votes
1answer
62 views

How to mix async socket io with aiohttp

I want to write http server with socket io. What I need: request --> socket io ask -> socket io answer -> response On http request, I send message to socket io client and wait response ...
0
votes
2answers
68 views

co_await expression requires a suitable “await_ready” function and none was found

The following code for a C=/WinRT UWP app produces an error "this co_await expression requires a suitable "await_ready" function and none was found". auto a = co_await Windows::Devices::Enumeration::...
1
vote
1answer
59 views

Android & Kotlin Coroutines: Is it possible to run out of threads?

How to find out if I am running out of threads in Android/Kotlin? I am building an app where I need to load a lot of data from a remote API. I add logs in my code to check for a thread name and I see ...
0
votes
1answer
52 views

Python coroutine time slicing

I am learning how to use coroutines from here and the article an video describes the following as an example Chess master Judit Polgár hosts a chess exhibition in which she plays multiple ...
3
votes
1answer
139 views

Recreate job after another job is completed

I have the following situation: job1 and job2 go to the server in the same time and both of them came back with status 401, which means that my token access has expired and I need to make a refresh. I ...
0
votes
1answer
43 views

Getting return value of generator via iteration

I am having a hard time reconciling these two: const gen = function *() { yield 3; yield 4; return 5; }; const rator = gen(); console.log(rator.next()); // { value: 3, done: false } console....
3
votes
2answers
195 views

How are Kotlin's Coroutines different from Java's Executor in Android?

I'm an Android developer switching from Java to Kotlin, and I am planning to use the coroutines to handle asynchronous code since it looks very promising. Back in Java, to handle asynchronous code I ...
2
votes
2answers
50 views

Output order display wrong

I getting a very weird issue. I have a hashmap list (groupList) in FragemtA. Everytime fragmentA is run, it should call checkUser function, and finally get the return value display at the forEach ...
2
votes
1answer
130 views

Java Synchronization issue - Main thread locked by the Coroutine implementation

I am working on a game, and I have a problem with thread synchronizations. I have failed miserably to write this properly so main thread does not hang because of this. Short story its creating a locks ...
1
vote
2answers
85 views

Convert callback hell to deferred object

Background: So, I have a pretty big project with a lot of API functions. I'm thinking of completely moving to coroutines, but as they are implemented as Callback and not Deferred, I can not use them ...
2
votes
1answer
61 views

Calling await() on suspend functions do not work correctly

private val coroutineSupervisor = SupervisorJob() protected val dispatcherProvider = CoroutineDispatcherProvider() protected val viewModelScope = CoroutineScope(dispatcherProvider.main + ...

http://mssss.yulina-kosm.ru