diff options
-rw-r--r-- | includes/Task.h | 1 | ||||
-rw-r--r-- | src/Task.cc | 7 | ||||
-rw-r--r-- | tests/test-Http.cc | 4 | ||||
-rw-r--r-- | tests/test-Sockets.cc | 4 |
4 files changed, 10 insertions, 6 deletions
diff --git a/includes/Task.h b/includes/Task.h index 19e5262..cb69ca3 100644 --- a/includes/Task.h +++ b/includes/Task.h @@ -170,6 +170,7 @@ class Task { } virtual void Do() = 0; void waitFor(Events::BaseEvent * event); + void sleep(double timeout); bool setOkayToEAgain(bool enable) { if (m_stackless) { AAssert(enable, "You can't make a task go not-okay-to-eagain if it's stackless."); diff --git a/src/Task.cc b/src/Task.cc index 4465203..9a00f30 100644 --- a/src/Task.cc +++ b/src/Task.cc @@ -174,6 +174,13 @@ struct ev_loop * Balau::Task::getLoop() { return getTaskMan()->getLoop(); } +void Balau::Task::sleep(double timeout) { + AAssert(!m_stackless && !m_okayToEAgain, "You can only call sleep on simple tasks."); + Events::Timeout evt(timeout); + waitFor(&evt); + yield(); +} + void Balau::Events::BaseEvent::doSignal() { Printer::elog(E_TASK, "Event at %p (%s) is signaled with cb %p and task %p", this, ClassName(this).c_str(), m_cb, m_task); m_signal = true; diff --git a/tests/test-Http.cc b/tests/test-Http.cc index 941d6a8..cd183ce 100644 --- a/tests/test-Http.cc +++ b/tests/test-Http.cc @@ -130,9 +130,7 @@ void MainTask::Do() { s->setLocal("localhost"); s->start(); - Events::Timeout timeout(1); - waitFor(&timeout); - yield(); + sleep(1); Events::TaskEvent stopperEvent; Task * stopper = TaskMan::registerTask(new Stopper, &stopperEvent); diff --git a/tests/test-Sockets.cc b/tests/test-Sockets.cc index 4ef0a78..0bcfc2a 100644 --- a/tests/test-Sockets.cc +++ b/tests/test-Sockets.cc @@ -39,9 +39,7 @@ class Client : public Task { public: virtual const char * getName() const { return "Test client"; } virtual void Do() { - Events::Timeout evt(0.1); - waitFor(&evt); - yield(); + sleep(0.1); char x, y; IO<Socket> s(new Socket()); |