{"id":15497338,"url":"https://github.com/jwerle/uv-emitter","last_synced_at":"2025-04-22T21:42:12.792Z","repository":{"id":11395714,"uuid":"13840491","full_name":"jwerle/uv-emitter","owner":"jwerle","description":"Event emitter in C with an API modeled after Node's EventEmitter using libuv","archived":false,"fork":false,"pushed_at":"2014-01-24T17:26:54.000Z","size":152,"stargazers_count":13,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T19:04:03.396Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","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/jwerle.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}},"created_at":"2013-10-24T18:26:31.000Z","updated_at":"2022-02-27T20:38:37.000Z","dependencies_parsed_at":"2022-08-22T08:50:23.765Z","dependency_job_id":null,"html_url":"https://github.com/jwerle/uv-emitter","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/jwerle%2Fuv-emitter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fuv-emitter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fuv-emitter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwerle%2Fuv-emitter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwerle","download_url":"https://codeload.github.com/jwerle/uv-emitter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250330227,"owners_count":21412947,"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":[],"created_at":"2024-10-02T08:32:54.869Z","updated_at":"2025-04-22T21:42:12.759Z","avatar_url":"https://github.com/jwerle.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"uv-emitter\n=========\n\nEvent emitter in C with an API modeled after Node's EventEmitter using libuv\n\n## install\n\n```sh\n$ clib install jwerle/uv-emitter\n```\n\n## usage\n\nUsing an the `getch()` function which [getch.h](https://github.com/jwerle/getch.h) implements you can get the keys pressed in stdin\n```c\n#include \u003cassert.h\u003e\n#include \u003cemitter.h\u003e\n#include \"getch.h\"\n\nstatic uv_loop_t *loop = NULL;\nstatic emitter_t *emitter = NULL;\n\nstatic void\nget_key (async_work_data_t *work);\n\nstatic void\non_keypress (void *ch);\n\nint\nmain (void) {\n  loop = uv_default_loop();\n  assert(loop);\n\n  emitter = emitter_new(loop);\n  assert(emitter);\n\n  assert(0 == emitter_on(emitter, \"keypress\", on_keypress));\n\n  async(env, loop) {\n    assert(env);\n    assert(loop);\n    wait(env, 500, get_key);\n  }\n\n  uv_run(loop, UV_RUN_DEFAULT);\n  return 0;\n}\n\nstatic void\nget_key (async_work_data_t *work) {\n  int ch = 0;\n  while (EOF != (ch = getch())) {\n    emitter_emit(emitter, \"keypress\", (void *) ch);\n  }\n}\n  \nstatic void\non_keypress (void *ch) {\n  printf(\"key = %c (%d)\\n\", (int) ch, (int) ch);\n}\n```\n\n## api\n\n### emitter_new(loop)\n\nAllocates a new `emitter_t *` pointer with a `uv_loop_t *` pointer bound\nto it.\n\n#### example\n\n```c\nemitter_t *emitter = emitter_new(uv_default_loop());\n```\n\n## types\n\n### emitter_event_cb\n\nA function pointer that is a callback bound to an event.\n\n```c\ntypedef void (emitter_event_cb)(void *data);\n```\n\n### emitter_event_t\n\nA structure that represents an event and its associated callbacks.\n\n```c\nasync_env_t         *env;     // async environment that the emitter is executed in\nstruct emitter      *emitter; // emitter struct that the event belongs to\nchar                *name;    // the name of the event\nvoid                *data;    // data, if any, to pass to the associated callbacks\nint                 cb_count; // the amount of callbacks associated with the event\nemitter_event_cb_t  *cbs[EMITTER_EVENT_MAX_CALLBACKS; // callbacks associated with this event\n```\n\n###\n\n## license\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fuv-emitter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwerle%2Fuv-emitter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwerle%2Fuv-emitter/lists"}