{"id":17680771,"url":"https://github.com/kcreate/events","last_synced_at":"2026-06-15T20:32:10.239Z","repository":{"id":72282708,"uuid":"65416683","full_name":"KCreate/events","owner":"KCreate","description":"Event API written for Crystal","archived":false,"fork":false,"pushed_at":"2016-12-12T16:16:50.000Z","size":24,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-23T13:16:48.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://crystal-lang.org","language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KCreate.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,"publiccode":null,"codemeta":null}},"created_at":"2016-08-10T21:09:35.000Z","updated_at":"2024-03-31T20:28:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"47761aaa-1cc7-4823-8d8f-05522bcb9f9a","html_url":"https://github.com/KCreate/events","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/KCreate/events","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KCreate%2Fevents","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KCreate%2Fevents/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KCreate%2Fevents/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KCreate%2Fevents/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KCreate","download_url":"https://codeload.github.com/KCreate/events/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KCreate%2Fevents/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34379915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-15T02:00:07.085Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-24T09:08:48.114Z","updated_at":"2026-06-15T20:32:10.211Z","avatar_url":"https://github.com/KCreate.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"[\u003cimg src=\"images/logo.png\" width=\"200\"\u003e](https://github.com/KCreate/events)\n\n[![Build Status](https://travis-ci.org/KCreate/events.svg?branch=master)](https://travis-ci.org/KCreate/events)\n\n# Events\n\nSuper basic event emitter written for crystal-lang.\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  events:\n    github: kcreate/events\n    branch: master\n```\n\n\n## Example\n\nJust include the module inside any classes you want to have access to the event methods\n\n```crystal\nrequire \"events\"\n\n# Some class\nclass Person\n  include Events\n\n  def initialize\n    add_event \"fart\"\n  end\n\n  def fart\n    invoke_event \"fart\"\n  end\nend\n\nleonard = Person.new\nleonard.on \"fart\", do\n  puts \"daaamn\"\nend\nleonard.fart\n```\n\nYou should see \"daaamn\" pop up in your console\n\n## Usage\n\nThe [test suite](spec/Events_spec.cr) has all the examples you need. I usually forget to update the README so just look there.\n\nYou first need a class that will emit some events. Add the module to your class like this:\n```crystal\nclass Person\n  include Events\nend\n```\n\nYou should add all your events inside your initialize function to prevent unexpected behaviour. Use *add_event* for this.\n```crystal\nclass Person\n  include Events\n\n  def initialize\n    add_event \"wakeup\"\n    add_event \"sleep\"\n  end\n\n  def wakeup\n    invoke_event \"wakeup\"\n  end\n\n  def gotosleep\n    invoke_event \"sleep\"\n  end\n\n  # ... The rest of your class\nend\n```\n\nSimilarly you can remove an event using *remove_event*. I don't know why you'd want to remove an event, but you can.\n```crystal\nclass Person\n  include Events\n\n  def initialize\n    add_event \"wakeup\"\n    add_event \"sleep\"\n  end\n\n  def wakeup\n    invoke_event \"wakeup\"\n  end\n\n  def gotosleep\n\n    # This first invokes the event and deletes it afterwards\n\n    invoke_event \"sleep\"\n    remove_event \"sleep\"\n  end\nend\n```\n\nYou can subscribe to these events from the outside like this:\n```crystal\nclass Person\n  ...\nend\n\nleonard = Person.new\n\nleonard.on \"wakeup\" do\n  puts \"leonard woke up\"\nend\n\nleonard.on \"sleep\" do\n  puts \"leonard went to sleep\"\nend\n```\n\nIf you now call the *wakeup* and *gotosleep* functions,\n```crystal\nleonard.gotosleep\nleonard.wakeup\n```\n\nThis will be the output in your console\n```sh\nleonard went to sleep\nleonard woke up\n```\n\nCalling the *on* function will add your handler to the event, but also return a proc that removes the handler from the event again.\nThis means you can do stuff like this:\n```crystal\nsleephandler = leonard.on \"sleep\" do\n    puts \"going to sleep\"\nend\n\nleonard.gotosleep # going to sleep\nleonard.gotosleep # going to sleep\n\nsleephandler.call # removing the handler\n\nleonard.gotosleep # ... nothing will be printed\n```\n\n## Test\n\nRun `crystal spec` to run the test suite.\n\n## Todos\n- Allow passing arguments to callbacks\n- Allow the usage of subclasses of `Event`\n- Add docs to a public website\n\n## Contributing\n\n1. Fork it ( https://github.com/kcreate/events/fork )\n2. Create your feature branch (git checkout -b my-new-feature)\n3. Commit your changes (git commit -am 'Add some feature')\n4. Make sure your changes don't break anything (crystal spec)\n5. Push to the branch (git push origin my-new-feature)\n6. Create a new Pull Request\n\n## Contributors\n\n- [kcreate](https://github.com/kcreate) Leonard Schuetz - creator, maintainer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkcreate%2Fevents","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkcreate%2Fevents","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkcreate%2Fevents/lists"}