{"id":13750684,"url":"https://github.com/matsumotory/mruby-timer-thread","last_synced_at":"2025-03-23T02:22:44.173Z","repository":{"id":66351621,"uuid":"83008570","full_name":"matsumotory/mruby-timer-thread","owner":"matsumotory","description":"Simple Timer Thread","archived":false,"fork":false,"pushed_at":"2018-03-31T04:44:32.000Z","size":42,"stargazers_count":0,"open_issues_count":3,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-18T18:16:55.997Z","etag":null,"topics":["mruby","thread","timer"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matsumotory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-02-24T06:20:47.000Z","updated_at":"2017-03-27T09:32:09.000Z","dependencies_parsed_at":"2023-02-28T08:45:49.333Z","dependency_job_id":null,"html_url":"https://github.com/matsumotory/mruby-timer-thread","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fmruby-timer-thread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fmruby-timer-thread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fmruby-timer-thread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matsumotory%2Fmruby-timer-thread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matsumotory","download_url":"https://codeload.github.com/matsumotory/mruby-timer-thread/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245045541,"owners_count":20552055,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mruby","thread","timer"],"created_at":"2024-08-03T08:00:44.234Z","updated_at":"2025-03-23T02:22:44.130Z","avatar_url":"https://github.com/matsumotory.png","language":"C","readme":"# mruby-timer-thread   [![Build Status](https://travis-ci.org/matsumotory/mruby-timer-thread.svg?branch=master)](https://travis-ci.org/matsumotory/mruby-timer-thread)\n\nSimple Timer Thread class\n\n## install by mrbgems\n- add conf.gem line to `build_config.rb`\n\n```ruby\nMRuby::Build.new do |conf|\n\n    # ... (snip) ...\n\n    conf.gem :github =\u003e 'matsumotory/mruby-timer-thread'\nend\n```\n## example\n\n- non blocking timer\n\n```ruby\ntimer_msec = 5000\n\n# 5sec timer\ntimer = Timer::MRubyThread.new\ntimer.run timer_msec\n\nwhile timer.running? do\n  sleep 1\n  puts \"master thread sleeping loop\"\nend\n\nputs \"timer thread finish.\"\n```\n\n- blocking timer\n\n```ruby\ntimer = Timer::MRubyThread.new\n\n\ntimer.run 3000\n\nputs \"main thread sleeping...\"\n\nsleep 1\n\nputs \"waiting timer\"\n\ntimer.blocking_handler do\n  puts \"finish timer\"\nend\n\nputs \"finish main thread\"\n```\n\n- POSIX timer\n  - NOTE: POSIX timer not available on MacOS\n\n```ruby\n# Specify signal name if you want (default ot SIGALRM as timer_create's default)\n# signal: nil will send no signal.\n# you can add handlers with mruby-signal or mruby-signal-thread\ntimer = Timer::POSIX.new(signal: nil)\ntimer.run 5000\n\n# You can create multiple timers (and are thread-safe by kernel)\nsleep 1\ntimer2 = Timer::POSIX.new(signal: nil)\ntimer2.run 5000\n\nwhile timer.running? or timer2.running? do\n  sleep 1\n  puts \"Timer1 running: #{timer.running?} and Timer2 running: #{timer2.running?}\"\nend\n# ...\n```\n\n- POSIX timer with interval\n\n```ruby\n# recommended mruby-signal-thread\nSignalThread.trap :USR2 do\n  puts \"Current datetime: #{`date`.chomp}\"\nend\n\ntimer = Timer::POSIX.new(signal: :USR2)\n\n# Invoke first timer after 5,000 msec,\n# then start interval timer every after 3,000 msec\n# like uv_timet_t or timer_create API\ntimer.run 5000, 3000\n\nCurrent datetime: Mon Mar 27 07:25:31 UTC 2017\nCurrent datetime: Mon Mar 27 07:25:34 UTC 2017\nCurrent datetime: Mon Mar 27 07:25:37 UTC 2017\nCurrent datetime: Mon Mar 27 07:25:40 UTC 2017\nCurrent datetime: Mon Mar 27 07:25:43 UTC 2017\n...\n```\n\n## License\nunder the MIT License:\n- see LICENSE file\n","funding_links":[],"categories":["Threads"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsumotory%2Fmruby-timer-thread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatsumotory%2Fmruby-timer-thread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatsumotory%2Fmruby-timer-thread/lists"}