Home » Developing U++ » UppHub » Coroutines package for U++
Coroutines package for U++ [message #59118] |
Sat, 05 November 2022 12:19  |
Oblivion
Messages: 1206 Registered: August 2007
|
Senior Contributor |
|
|
Hi,
I have added an experimental CoRoutines package to both UppHub and upp-components repo.
It provides a simple and basic interface for building coroutines.
Main github repo (for pull request etc.):
There are two types of CoRoutine in the package:
CoRoutine -> A regular coroutine that can return any value (or void)
CoGenerator -> A regular generator type function.
- The classes provided with the package expose "traditional" Upp-like interface (Do(), Get(), Pick() and Next() -methods, depending on their type.)
- Allows exception handling and propagation.
- Also an example code is included.
Example:
#include <Core/Core.h>
#include "CoRoutine.h"
using namespace Upp;
CoRoutine<Vector<int>> CoMakeIota(int begin, int end, int step)
{
Vector<int> v;
for(int i = begin; i < end; i += step) {
v.Add(i);
RLOG(__func__);
co_await CoSuspend();
}
co_return v;
}
CoGenerator<int> CoGenerateNumbers()
{
int i = 0;
for(;;) {
RLOG(__func__);
co_yield i++;
}
}
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
auto co1 = CoMakeIota(0, 10, 2);
auto co2 = CoGenerateNumbers();
try {
while(co1.Do())
RLOG(__func__); // NOP;
auto v = co1.Pick();
RDUMP(v);
for(int i = 0; i < 10; i = co2.Next())
RDUMP(i);
}
catch(...) {
RLOG("Unhandled exception");
}
}
Suggestion, pull requests, reviews, etc. are welcome.
Best regards,
Oblivion
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Sat, 05 November 2022 14:44] Report message to a moderator
|
|
|
 |
|
Coroutines package for U++
By: Oblivion on Sat, 05 November 2022 12:19
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Sun, 06 November 2022 20:20
|
 |
|
Re: Coroutines package for U++
By: Klugier on Sun, 06 November 2022 20:44
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Sun, 06 November 2022 21:31
|
 |
|
Re: Coroutines package for U++
By: Lance on Mon, 07 November 2022 00:14
|
 |
|
Re: Coroutines package for U++
By: koldo on Mon, 07 November 2022 08:39
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 07 November 2022 20:07
|
 |
|
Re: Coroutines package for U++
By: peterh on Mon, 07 November 2022 20:30
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 07 November 2022 20:31
|
 |
|
Re: Coroutines package for U++
By: peterh on Tue, 08 November 2022 09:09
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Wed, 09 November 2022 16:22
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Wed, 09 November 2022 22:52
|
 |
|
Re: Coroutines package for U++
By: Lance on Wed, 09 November 2022 23:26
|
 |
|
Re: Coroutines package for U++
By: Lance on Sat, 12 November 2022 00:33
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Sat, 12 November 2022 07:22
|
 |
|
Re: Coroutines package for U++
By: Lance on Sun, 13 November 2022 05:37
|
 |
|
Re: Coroutines package for U++
By: Lance on Mon, 14 November 2022 02:17
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 14 November 2022 05:56
|
 |
|
Re: Coroutines package for U++
By: Lance on Mon, 14 November 2022 15:08
|
 |
|
Re: Coroutines package for U++
By: peterh on Mon, 07 November 2022 18:38
|
 |
|
Re: Coroutines package for U++
By: zsolt on Mon, 12 December 2022 13:48
|
 |
|
Re: Coroutines package for U++
By: Oblivion on Mon, 12 December 2022 17:42
|
 |
|
Re: Coroutines package for U++
By: zsolt on Mon, 12 December 2022 21:38
|
Goto Forum:
Current Time: Sat May 10 14:25:30 CEST 2025
Total time taken to generate the page: 0.00493 seconds
|