U++ framework
Do not panic. Ask here before giving up.

Home » Community » U++ community news and announcements » CoWork exceptions and IsCanceled
CoWork exceptions and IsCanceled [message #48821] Sun, 01 October 2017 13:52
mirek is currently offline  mirek
Messages: 14291
Registered: November 2005
Ultimate Member
CoWork now can handle worker thread exceptions:

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	StdLogSetup(LOG_COUT|LOG_FILE);
	
	try {
		CoWork co;
		co & [] { throw "Worker exception"; };
	}
	catch(const char *s) {
		LOG("Caught: " << s);
	}
}


Cancelation of CoWork is now propagated to worker threads via "IsCanceled" static method:

#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	StdLogSetup(LOG_COUT|LOG_FILE);

	CoWork co;
	for(int i = 0; i < 50; i++)
		co & [] {
			for(;;) {
				if(CoWork::IsCanceled()) {
					LOG("CoWork is canceled");
					return;
				}
				Sleep(1);
			}
		};
	Sleep(100);
	co.Cancel();
}
Previous Topic: WebSocket refactored
Next Topic: ArrayCtrl::Column lambda cleanup
Goto Forum:
  


Current Time: Mon May 04 20:52:46 GMT+2 2026

Total time taken to generate the page: 0.00918 seconds