coroutine

How to Use IEnumerator Correctly when button calls multiple functions

非 Y 不嫁゛ 提交于 2020-06-29 04:33:41
问题 I am making a card game in which I am trying to make a (0.5f) delay before each card is instantiated. I have my code which instantiates and object public IEnumerator Name(int x,int y, int z) { } In the IEnum i have a yeild return new WaitForSeconds(0.5f) before all the code with the instantiation. I call my IEnumerator in 2 different classes 2 times in each by using StartCoroutine(Name(...par...)); And on my play game button i have 4 events which use the enum to spawn the cards but there is

How do yield-based coroutines in Python differ from coroutines with @asyncio.coroutine and @types.coroutine decorators?

梦想的初衷 提交于 2020-06-28 01:51:53
问题 I have been trying to understand asynchronous programming, particularly in Python. I understand that asyncio is built off of an event loop which schedules the execution of coroutines, but I have read about several different ways to define coroutines, and I am confused how they all relate to each other. I read this article for more background information on the topic. Although it covers each of the four types of coroutines I have mentioned, it does not entirely describe how they differ.

How do yield-based coroutines in Python differ from coroutines with @asyncio.coroutine and @types.coroutine decorators?

岁酱吖の 提交于 2020-06-28 01:51:23
问题 I have been trying to understand asynchronous programming, particularly in Python. I understand that asyncio is built off of an event loop which schedules the execution of coroutines, but I have read about several different ways to define coroutines, and I am confused how they all relate to each other. I read this article for more background information on the topic. Although it covers each of the four types of coroutines I have mentioned, it does not entirely describe how they differ.

Kotlin: coroutineScope is slower than GlobalScope

不羁岁月 提交于 2020-06-27 12:51:48
问题 I'm learning coroutines, and I encounter the following surprising (for me) behavior. I want to have a parallel map. I consider 4 solutions: Just map , no parallelism pmap from here. Modification of item 2: I removed coroutineScope and use GlobalScope . Java's parallelStream . The code: import kotlinx.coroutines.* import kotlin.streams.toList import kotlin.system.measureNanoTime inline fun printTime(msg: String, f: () -> Unit) = println("${msg.padEnd(15)} time: ${measureNanoTime(f) / 1e9}")

Why must the return type of a coroutine be move-constructible?

走远了吗. 提交于 2020-06-26 18:06:44
问题 Consider the following code that defines the invoker class - a minimal return type for a coroutine. We explicitly delete the copy and move constructors of the invoker class. #include <coroutine> #include <cstdlib> class invoker { public: class invoker_promise { public: invoker get_return_object() { return invoker{}; } auto initial_suspend() { return std::suspend_never{}; } auto final_suspend() { return std::suspend_never{}; } void return_void() {} void unhandled_exception() { std::abort(); }

Unresolved reference: async in Kotlin in 1.3

ε祈祈猫儿з 提交于 2020-06-25 10:50:14
问题 I have multi module kotlin gradle project in github here. One of my sub project introducing-coroutines with build file build.gradle.kts file is here The contents of build.gradle.kts is - import org.jetbrains.kotlin.gradle.dsl.Coroutines import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java kotlin("jvm") version "1.3.11" } group = "chapter2" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { compile(kotlin("stdlib-jdk8")) compile("org.jetbrains.kotlinx

Unresolved reference: async in Kotlin in 1.3

心已入冬 提交于 2020-06-25 10:49:20
问题 I have multi module kotlin gradle project in github here. One of my sub project introducing-coroutines with build file build.gradle.kts file is here The contents of build.gradle.kts is - import org.jetbrains.kotlin.gradle.dsl.Coroutines import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { java kotlin("jvm") version "1.3.11" } group = "chapter2" version = "1.0-SNAPSHOT" repositories { mavenCentral() } dependencies { compile(kotlin("stdlib-jdk8")) compile("org.jetbrains.kotlinx

Kotlin coroutines handle error and implementation

好久不见. 提交于 2020-06-24 07:35:36
问题 Using coroutines for the first time. Need help. Here is my flow: Presenter wants to login so calls Repository Interface. Repository implements RepositoryInterface. So Repository calls APIInterface. APIInterface is implemented by APIInterfaceImpl. The APIInterfaceImpl finally calls the MyRetrofitInterface. Here is the flow diagrammatically: Presenter -> Repository -> APIInterfaceImpl -> MyRetrofitInterface Once I get login response: APIInterfaceImpl -> Repository -> Stores the data in cache ->

Why must the return type of a coroutine be move-constructible?

无人久伴 提交于 2020-06-23 06:49:49
问题 Consider the following code that defines the invoker class - a minimal return type for a coroutine. We explicitly delete the copy and move constructors of the invoker class. #include <coroutine> #include <cstdlib> class invoker { public: class invoker_promise { public: invoker get_return_object() { return invoker{}; } auto initial_suspend() { return std::suspend_never{}; } auto final_suspend() { return std::suspend_never{}; } void return_void() {} void unhandled_exception() { std::abort(); }

How to shutdown the loop and print error if coroutine raised an exception with asyncio?

坚强是说给别人听的谎言 提交于 2020-06-10 02:32:26
问题 Suppose I have a few coroutines running in a loop. How to make so that if some of them failed with exception the whole program would fail with this exception? Because right now asyncio doesn't even prints the error messages from coroutines unless I use logging level "DEBUG". from asyncio import get_event_loop, sleep async def c(sleep_time=2, fail=False): print('c', sleep_time, fail) if fail: raise Exception('fail') while True: print('doing stuff') await sleep(sleep_time) loop = get_event_loop