void producer_consumer_sample()
{
	putchar('\n');
	puts(__FUNCTION__);
	putchar('\n');

	consumer(RfNew Coroutine(boost::bind(filter, RfNew Coroutine(producer))));
}
Exemplo n.º 2
0
int CScriptCoroutine::ThreadFnc() {
	int ret=-1;
	try {
		ret = Coroutine();
	} catch(StopIteration_t &) {
		return 0;
	} catch(std::exception & e) {
		printf("CScriptCoroutine has received an uncaught exception: %s\n", e.what());
		return -1;
	} catch(...) {
		printf("CScriptCoroutine has received an uncaught and unknown exception\n");
		return -1;
	}
	return ret;
}
void permgen_sample()
{
	putchar('\n');
	puts(__FUNCTION__);
	putchar('\n');

	int a[3] = {1, 2, 3};
	CoroutinePtr co = RfNew Coroutine(boost::bind(permgen, a, 3));

	for (int *p = co->resume<int*>(); co->status() != Coroutine::eDEAD; p = co->resume<int*>())
	{
		for (size_t i = 0; i < 3; ++i)
		{
			printf("%d ", p[i]);
		}
		putchar('\n');
	}
}
//==============================================================================
ExpressionParser::ExpressionParser()
{
  parseCoroutine_ = boost::move(Coroutine(boost::bind(&ExpressionParser::ParseTopLevelExpression_, this, _1), Token()));
}
Exemplo n.º 5
0
    void test (int chunkSize, Strings const& expected)
    {
        auto name = std::to_string (chunkSize);
        setup (name);

        std::string buffer;
        Json::Output output = Json::stringOutput (buffer);

        auto makeContinuation = [&] (std::string const& data) {
            return Continuation ([=] (Callback const& cb) {
                output (data + " ");
                cb();
            });
        };

        Strings result;
        SuspendCallback suspendCallback ([&] (Suspend const& suspend)
        {
            Callback yield = suspendForContinuation (
                suspend, makeContinuation ("*"));
            auto out = chunkedYieldingOutput (output, yield, chunkSize);
            out ("hello ");
            result.push_back (buffer);

            suspend (makeContinuation("HELLO"));
            result.push_back (buffer);

            out ("there ");
            result.push_back (buffer);

            suspend (makeContinuation("THERE"));
            result.push_back (buffer);

            out ("world ");
            result.push_back (buffer);

            suspend (makeContinuation("WORLD"));
            result.push_back (buffer);
        });

        Coroutine (suspendCallback).run();
        expectCollectionEquals (result, expected);

        static
        auto const printResults = false;
        if (! printResults)
            return;

        std::string indent1 = "        ";
        std::string indent2 = indent1 + "           ";

        std::cerr << indent1 << "test (" + name + ", {";
        for (auto i = 0; i < result.size(); ++i) {
            if (i)
                std::cerr << ",";
            std::cerr << "\n" << indent2;
            std::cerr << '"' << result[i] << '"';
        }
        std::cerr << "\n" << indent2 << "});\n";
        expect(true);
    }
Exemplo n.º 6
0
Coroutine Async__(const coroutine_proc_type &func)
{
	return Coroutine(func);
}
Exemplo n.º 7
0
Coroutine GetCurrentCoroutine()
{
	return Coroutine(CoroutineManager::getInstance().top());
}