Questions tagged [coroutine]
Coroutines are a general control structure whereby flow control is cooperatively passed between two different routines without returning.
2,297
questions
0
votes
0
answers
11
views
When changing scenes, the Script that contains an Invoke() gives an error
I have an Invoke() inside a Coroutine. This Invoke() looks like this:
private IEnumerator aguardarResultado()
{
while(!_rigidbody.IsSleeping())
{
yield return null;
}
int ...
0
votes
1
answer
13
views
Test suspended function returning Flow in runTest Scope is not finishing. After time it giving timeout error
I am testing the suspend function that returns the flow. I am able to collect that flow in the runTest scope but this test never ends and gives a timeout error after sometime.
suspend fun getData() : ...
0
votes
0
answers
29
views
How to run coroutines in cucumber?
I am using kotlin and cucumber. I made a simple mokeserver that I would like to run in my tests. I wanted to start running it in a step in the background without the test getting stuck on the step. I ...
1
vote
1
answer
37
views
How to use Unity StopCoroutine when the Coroutine relies on mulitple conditions?
I have recently been messing with the Coroutine features in Unity and realised that I could not seem to stop a coroutine that relied on conditions with the StopCoroutine command.
My code is as follows:...
0
votes
0
answers
27
views
Kotlin Multiplatform Mobile (KMM) WebSocket code connecting twice on iOS
I'm working on a Kotlin Multiplatform Mobile (KMM) project where I'm using WebSockets to send and receive messages. I have been following the ktor client and server guides for a simple chat app. ...
-1
votes
2
answers
74
views
How to create better coroutines in Python [duplicate]
I want to create two asynchronic functions, and I don't know when I will need to run any of them, but they have to not interrupt each other
import asyncio
async def func1():
await asyncio.sleep(1)...
0
votes
2
answers
74
views
C# using library with awaitable async methods in Unity without locking the main thread
I have a script like this:
public class Example : Monobehaviour
{
public async void Start()
{
LibraryClass service = new LibraryClass();
bool result = await service.Login();
...
0
votes
0
answers
19
views
Unit testing ViewModel functions that calls other suspending functions within a viewModelScope
I'm trying to test a ViewModel whereby it contains a function that calls another suspending function of a library, then assign its return value to an internal state.
I want to uni test this function, ...
0
votes
1
answer
38
views
how to start IEnumerator again after SetActive(false);
I am trying to create a picture function in my game, and I want the picture frame to vanish after a couple seconds. After I did that, when I tried to take the picture again, it wont work. I am very ...
0
votes
1
answer
52
views
How can i get different data combined in flow in android?
I am developing an application.
There is one problem.
I have one screen that displays a list of topics.
I would like to display different data combined. One is the topic entity and the other is the ...
0
votes
1
answer
32
views
python asyncio `loop.create_task` add task in another thread's loop, the task randomly get stucked
console's output
the code:
import asyncio
import time
from threading import Thread
import threading
loop = asyncio.new_event_loop()
def print_ids(s, l):
print(f"{threading.current_thread()....
0
votes
0
answers
42
views
how to bind one thread to one queue? Is it mpsc?
Is it my understanding of actor model, mpmc and mpsc right?
I have seen some code like this before:
public enum ProcessorId implements CommandProcessorId {
AUTH,
PLAYER,
PERSIST,
...
0
votes
1
answer
46
views
GCC interrupts compiling with this message "internal compiler error: in instantiate_type" on simple coroutine
I get GCC compiler internal error message when compile my code. But MSVC and Clang compile it fine.
This is reduced to example one simple "yield coroutine".
I use x86-64 gcc 13.2 compiler ...
0
votes
0
answers
14
views
Passing coroutine result as function argument
I'm a beginner to asynchronous programming and AsyncIO module.
I'm trying to send a get request to a web API using async functions and then store the result in a JSON file using another functions by ...
-1
votes
1
answer
59
views
Is there a way to delay execution without a coroutine in C#? [duplicate]
I need to delay something in my script, but I cannot use a coroutine as the line I need to execute relies on reading the parameter Collider2D other from the OnTriggerEnter2D function it's written in.
...
0
votes
1
answer
64
views
How can I run a coroutine faster than Update() in Unity / c#
The problem is that it usually caps itself to the framerate of the game. I believe this is due to yield waiting a frame. So is there any way I can run some code at say 8000 times per second in a ...
1
vote
1
answer
69
views
How can I return an immovable object from a C++ coroutine?
As of C++17, normal functions can return non-movable non-copyable values. Silly example:
std::lock_guard<std::mutex> silly() {
return std::lock_guard<std::mutex>(my_mutex);
}
What must ...
0
votes
0
answers
42
views
Kotlin Flow - Code not being executed inside collect block in view model
I don't understand why collect block not being executed, usually this is not an issue in my earlier projects. Actually the function is run well, just I cannot collect the result.
ViewModel.
fun ...
0
votes
0
answers
43
views
ObjectDisposedException generates when the list item's parent is not active
I am using vuforia. OnTargetFound the parent object will be setActive true, a list will be populated with reference of its children, a will start holding the process of some calculations in while loop ...
0
votes
0
answers
28
views
How to implement coroutine dispatcher for java android?
So I was watching Android Developers channel on how to build data layer and at 19:18 I see him use the following code
val taskId = withContext(dispatcher){
createTaskId()
}
Now given that
this ...
1
vote
2
answers
46
views
Memory Leak in Fragment due to infinite loop under lifecycle scope of coroutine
Description:
I've encountered an issue in my application where the performance degrades over time and appears to be related to a potential memory leak. Here's the setup:
Scenario:
The main screen ...
0
votes
1
answer
56
views
Custom awaitable and resumption with ASIO coroutines
I have the following class representing a connection in ASIO (I omitted the bits not pertinent to the issue):
template<Enumeration T>
class connection : public std::enable_shared_from_this<...
0
votes
2
answers
57
views
Why my ProgressBar is showing up after inline coroutine function, instead of before?
When I'm sending HTTP requests to server from my tablet by using Fuel, I want to display a ProgressBar at screen before the concerned function begins to run. But for an unknow reason, it's happened ...
1
vote
1
answer
66
views
How to return the results from a coroutine object with asyncio?
I'm attempting to learn how to run asynchronous code in google co-labs with asyncio. However, I am having issues returning the results.
An example I set up for myself looks like this:
async def main():...
-2
votes
1
answer
78
views
python await multiple queues, events, etc
I'd like to await multiple asyncio queues, events, etc. When you have coroutines wrapping futures that are already being fulfilled by other tasks, there is absolutely no point in creating yet another ...
0
votes
1
answer
93
views
Suspend Coroutines's execution for multiple callback update
I can use suspendCoroutine or suspendCancellableCoroutine to work with callbacks (to convert a callback to a suspend function): but how to send result multiple times the result. Use of flow also didn'...
0
votes
1
answer
39
views
Coroutine does not work on two Line Renderers simultaneously
I'm pretty new to coding, and I'm working on this game on Unity in c#, where you can draw a line with your mouse and it automatically erases after 1.5s, progressively from start point to end point.
...
0
votes
1
answer
34
views
Why do inline awaits, apparently, run synchronously but awaits on Deferreds run in parallel?
In the following telemeter function, I measure elapsed time for two blocks of code. The first declares Deferreds which are later awaited. The second awaits each Deferred inline.
Since await claims to &...
0
votes
1
answer
31
views
Unit Testing ViewModel - Data in returned object is always null
This is my ViewModel
@HiltViewModel
class MovieDetailsViewModel @Inject constructor(
private val repository: MovieRepository,
private val savedStateHandle: SavedStateHandle,
private val ...
0
votes
0
answers
6
views
terminology: does "closure" refer more to definition or to instance?
motivating example in python, though this is not python-specific.
def make_foo(x):
def foo(y):
return x + y
def make_bar(x):
def bar(y):
return x - y
f = make_foo(1)
b1 = make_bar(1)
b2 =...
0
votes
1
answer
19
views
What is an efficient way of returning values in viewmodel scopes / function scopes in kotlin
I have a QuestDetailScreen in which I call getDailyQById(id), which passes to a viewmodel -> repo -> dao -> database. I use LiveData in the viewmodel for the DailyQuest vals. To not have the ...
0
votes
0
answers
26
views
Question Python task's(created from coroutine) implementation and concurrent semantics
import asyncio
import time
async def say_after(delay, what):
await asyncio.sleep(delay)
print(what)
async def main():
print(f"started at {time.strftime('%X')}")
await ...
1
vote
1
answer
37
views
Assistance required with coroutines in roblox studio
I'm trying to make multiple enemies move at once so I'm trying to use coroutines to do it. However, I keep getting this error: "ServerScriptService.Main.Mob:28: invalid argument #1 to 'wrap' (...
1
vote
0
answers
101
views
Double-free error in coroutine that takes aggregate parameter
The following code works correctly in the newest versions of GCC and Clang, but results in a double-free in GCC 11 to GCC 12, as illustrated at https://godbolt.org/z/z66qYaxcG.
#include <coroutine&...
1
vote
0
answers
32
views
Unity Top-Down Dashing
Trying to Create Dash feature to my top-down game and when I press space I can see the velocity changing by looking at the console but in actual gameplay it won't change a bit.
What am I missing? I ...
0
votes
0
answers
33
views
Unity: Why downloading a text asset from internet doesn't work?
I tried to use a coroutine to download a get a text by UnityWebRequest.Get(url);
In the NetworkManager Class, I have these two exactly identical Coroutines but in different name:
public static ...
0
votes
0
answers
16
views
Could update scheduled events while it is in sleeping mode in asyncio?
What I need to do is: after I create an event that sleeps for example about 10 seconds to run the task after the 10 seconds is finished, may someone need to do a new event which will decrease this 10 ...
0
votes
0
answers
31
views
Shared resource in asio coroutine
I have some code like the following and want to prevent concurrent access to a shared resource using asio without using an explicit mutex or lock.
asio::io_context context(1) // This indicates to use ...
0
votes
1
answer
41
views
Properly use a loop in coroutine to place rest api call
I am currently building a Flickr-like app and I do have a question about pagination.
I am currently calling a FlickrApi to retrieve the recent photos. It's working well but I only get the first 100 ...
0
votes
0
answers
46
views
How to fix "Coroutine object is not callable" type hint warning?
I'm having troubles with type hinting in my async pytest fixtures.
Fixture 1:
@pytest.fixture(scope='function')
async def create_raw_user(asyncpg_pool) -> Callable[[str, str, str], Awaitable[None]]:...
0
votes
2
answers
44
views
Run action every minute sharp using kotlin coroutines
I believe this can be done, just don't know that is the best API to easily achieve this...
Basically, I have the following method:
private val tickerPeriod = 1.minutes
private suspend fun ...
0
votes
2
answers
28
views
I'm doing both operation updating the item and sorting in list in Default Dispatcher java.util.ConcurrentModificationException error is coming
While i'm using Default Dispatcher for updating the items in list and then sort the list i some time face
java.util.ConcurrentModificationException error. Question is do i have to make two difference
...
0
votes
1
answer
61
views
How to call apis with Kotlin coroutines in chain
I am quite new to kotlin world and coroutines.
I am trying to send API request with webClient. But it should be in order because the second API call depends of data as param from the first API call. ...
1
vote
2
answers
68
views
Understanding CoroutineScope(Job() + Dispatchers.Main) syntax
I know what a job is (handle to a coroutine), what a Dispatcher is (threadpool it runs on) and what a CoroutineScope is (well, a scope or we could also say a kind of group) , yet I don't understand ...
1
vote
3
answers
121
views
Kotlin - Suspend functions in one threaded environments
I'm not entirely sure if my mental model of suspend is correct. From what I gathered it seems to mean that a (long running) suspend function can be suspended if another function inside it is marked ...
1
vote
0
answers
70
views
kotlin test of async seems to blocks in main routine, but main never starts processing again
Note: I have edited the test after finding Kotlin doc on tests for coroutines. I've switched from runBlocking to runTest(UnconfinedTestDispatcher()), with no difference.
I've included the trace at ...
1
vote
0
answers
23
views
Always gets a blue screen for writing a specific IEnumerator method for a coroutine (Unity 2D, c#, script)
Every time I finally get my IEnumerator method for a coroutine finally able to return a value, I get a blue screen and my hierarchy is empty. Is there something wrong with my code so I get a blue ...
1
vote
2
answers
93
views
Safely accessing the this pointer in a class-member coroutine
The problem is that the object may be destroyed before the coroutine finishes.
I've already solved this problem by using C++/WinRT tools. But I'm interested in how you could solve it with the c++ ...
3
votes
3
answers
206
views
Avoiding extra `next` call after `yield from` in Python generator
Please see the below snippet, run with Python 3.10:
from collections.abc import Generator
DUMP_DATA = 5, 6, 7
class DumpData(Exception):
"""Exception used to indicate to yield ...
0
votes
1
answer
142
views
Kotlin Coroutines: on which thread the suspend function runs on?
I am new to Kotlin Coroutines and I have a question that I am not able to find a direct answer anywhere. The question is simple: if I have a coroutine and I call a suspend function (which could ...