1+
12# concurrencpp, the C++ concurrency library
23
34[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
@@ -682,51 +683,27 @@ class timer_queue {
682683 */
683684 bool shutdown_requested() const noexcept;
684685
685-
686- /*
687- Creates a new running timer where *this is the associated timer_queue.
688- Throws std::invalid_argument if executor is null.
689- Throws errors::timer_queue_shutdown if shutdown had been called before.
690- */
691- template<class callable_type>
692- timer make_timer(
693- size_t due_time,
694- size_t frequency,
695- std::shared_ptr<concurrencpp::executor> executor,
696- callable_type&& callable);
697-
698686 /*
699687 Creates a new running timer where *this is associated timer_queue.
700688 Throws std::invalid_argument if executor is null.
701689 Throws errors::timer_queue_shutdown if shutdown had been called before.
702690 */
703691 template<class callable_type, class ... argumet_types>
704692 timer make_timer(
705- size_t due_time,
706- size_t frequency,
693+ std::chrono::milliseconds due_time,
694+ std::chrono::milliseconds frequency,
707695 std::shared_ptr<concurrencpp::executor> executor,
708696 callable_type&& callable,
709697 argumet_types&& ... arguments);
710698
711- /*
712- Creates a new one shot timer where *this is associated timer_queue.
713- Throws std::invalid_argument if executor is null.
714- Throws errors::timer_queue_shutdown if shutdown had been called before.
715- */
716- template<class callable_type>
717- timer make_one_shot_timer(
718- size_t due_time,
719- std::shared_ptr<concurrencpp::executor> executor,
720- callable_type&& callable);
721-
722699 /*
723700 Creates a new one shot timer where *this is associated timer_queue.
724701 Throws std::invalid_argument if executor is null.
725702 Throws errors::timer_queue_shutdown if shutdown had been called before.
726703 */
727704 template<class callable_type, class ... argumet_types>
728705 timer make_one_shot_timer(
729- size_t due_time,
706+ std::chrono::milliseconds due_time,
730707 std::shared_ptr<concurrencpp::executor> executor,
731708 callable_type&& callable,
732709 argumet_types&& ... arguments);
@@ -736,7 +713,7 @@ class timer_queue {
736713 Throws std::invalid_argument if executor is null.
737714 Throws errors::timer_queue_shutdown if shutdown had been called before.
738715 */
739- result<void> make_delay_object(size_t due_time, std::shared_ptr<concurrencpp::executor> executor);
716+ result<void> make_delay_object(std::chrono::milliseconds due_time, std::shared_ptr<concurrencpp::executor> executor);
740717};
741718```
742719
@@ -778,7 +755,7 @@ class timer {
778755 Returns the due time in milliseconds the timer was defined with.
779756 Throws concurrencpp::errors::empty_timer is *this is empty.
780757 */
781- size_t get_due_time() const;
758+ std::chrono::milliseconds get_due_time() const;
782759
783760 /*
784761 Returns the executor the timer was defined with.
@@ -796,13 +773,13 @@ class timer {
796773 Returns the frequency in milliseconds the timer was defined with.
797774 Throws concurrencpp::errors::empty_timer is *this is empty.
798775 */
799- size_t get_frequency() const;
776+ std::chrono::milliseconds get_frequency() const;
800777
801778 /*
802779 Sets new frequency for this timer. Callables that have been scheduled to run at this point are not affected.
803780 Throws concurrencpp::errors::empty_timer is *this is empty.
804781 */
805- void set_frequency(size_t new_frequency);
782+ void set_frequency(std::chrono::milliseconds new_frequency);
806783
807784 /*
808785 Returns true is *this is not an empty timer, false otherwise.
@@ -817,19 +794,21 @@ class timer {
817794
818795#include <iostream>
819796
797+ using namespace std::chrono_literals;
798+
820799int main() {
821800 concurrencpp::runtime runtime;
822801 std::atomic_size_t counter = 1;
823802 concurrencpp::timer timer = runtime.timer_queue()->make_timer(
824- 1'500 ,
825- 2'000 ,
803+ 1'500ms ,
804+ 2'000ms ,
826805 runtime.thread_pool_executor(),
827806 [&] {
828807 const auto c = counter.fetch_add(1);
829808 std::cout << "timer was invoked for the " << c << "th time" << std::endl;
830809 });
831810
832- std::this_thread::sleep_for(std::chrono::seconds(12) );
811+ std::this_thread::sleep_for(12s );
833812 return 0;
834813}
835814```
@@ -845,16 +824,18 @@ A oneshot timer is a one-time timer with only a due time - after it schedules it
845824
846825#include < iostream>
847826
827+ using namespace std ::chrono_literals;
828+
848829int main() {
849830 concurrencpp::runtime runtime;
850831 concurrencpp::timer timer = runtime.timer_queue()->make_one_shot_timer(
851- 3'000 ,
832+ 3'000ms ,
852833 runtime.thread_executor(),
853834 [ &] {
854835 std::cout << "hello and goodbye" << std::endl;
855836 });
856837
857- std::this_thread::sleep_for (std::chrono::seconds (4) );
838+ std::this_thread::sleep_for(4s );
858839 return 0;
859840}
860841```
@@ -870,6 +851,8 @@ A delay object is a result object that becomes ready when its due time is reache
870851
871852#include <iostream>
872853
854+ using namespace std::chrono_literals;
855+
873856concurrencpp::null_result delayed_task(
874857 std::shared_ptr<concurrencpp::timer_queue> tq,
875858 std::shared_ptr<concurrencpp::thread_pool_executor> ex) {
@@ -879,15 +862,15 @@ concurrencpp::null_result delayed_task(
879862 std::cout << "task was invoked " << counter << " times." << std::endl;
880863 counter++;
881864
882- co_await tq->make_delay_object(1'500 , ex);
865+ co_await tq->make_delay_object(1'500ms , ex);
883866 }
884867}
885868
886869int main() {
887870 concurrencpp::runtime runtime;
888871 delayed_task(runtime.timer_queue(), runtime.thread_pool_executor());
889872
890- std::this_thread::sleep_for(std::chrono::seconds(10) );
873+ std::this_thread::sleep_for(10s );
891874 return 0;
892875}
893876```
@@ -1107,5 +1090,5 @@ In this example, we created an executor which logs actions like enqueuing a task
11071090
11081091### Supported platforms
11091092* Linux (requires clang-9 and above).
1110- * machOS (requires clang-9 and above).
1093+ * macOS (requires clang-9 and above).
11111094* Windows (requires Windows 10, visual studio 2019 and above).
0 commit comments