{"id":16786424,"url":"https://github.com/nklbdev/suby-csharp","last_synced_at":"2025-03-16T23:23:20.678Z","repository":{"id":101263209,"uuid":"134481714","full_name":"nklbdev/suby-csharp","owner":"nklbdev","description":"Better events","archived":false,"fork":false,"pushed_at":"2018-10-23T13:02:11.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-23T09:33:04.687Z","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/nklbdev.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":"2018-05-22T22:15:50.000Z","updated_at":"2018-10-23T13:02:17.000Z","dependencies_parsed_at":"2023-06-09T00:45:15.159Z","dependency_job_id":null,"html_url":"https://github.com/nklbdev/suby-csharp","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nklbdev%2Fsuby-csharp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nklbdev%2Fsuby-csharp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nklbdev%2Fsuby-csharp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nklbdev%2Fsuby-csharp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nklbdev","download_url":"https://codeload.github.com/nklbdev/suby-csharp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243945715,"owners_count":20372920,"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-13T08:12:12.603Z","updated_at":"2025-03-16T23:23:20.650Z","avatar_url":"https://github.com/nklbdev.png","language":"C#","readme":"# Suby\n\n[![Build status](https://ci.appveyor.com/api/projects/status/boxmp393o0u878kv?svg=true)](https://ci.appveyor.com/project/nklbdev/suby-csharp)\n[![NuGet version](https://badge.fury.io/nu/suby.nklbdev.svg)](https://www.nuget.org/packages/suby.nklbdev)\n[![CodeFactor](https://www.codefactor.io/repository/github/nklbdev/suby-csharp/badge)](https://www.codefactor.io/repository/github/nklbdev/suby-csharp)\n\nAlternate thread-safe events for C#\n\n## The problems it solves\n\n- Necessity of checking the event for null before raising\n- Necessity to store a reference to the event owning object in subscribers\n- The problem of ownership of the event, or just subscription\n- The problem of notifying some listeners after they have been unsubscribed, if the current notification cycle has not yet ended\n\n### Installing\n\nUse NuGet Package Manager Console:\n\n```\nInstall-Package suby.nklbdev\n```\n\n## How to use\n\nTo create an event simply call one of default constructors:\n```cs\nvar e0 = new Event();\nvar e1 = new Event\u003cstring\u003e();\nvar e2 = new Event\u003cstring, int\u003e();\n```\n... and so on\n\nThen subscribe to the event:\n```cs\nvar sub = e1.Subscribe(s =\u003e\n    Console.WriteLine($\"You got new message: {s}\"));\n```\n\nThen raise the event:\n```cs\ne1.Raise(\"Hello!\");\n```\n\nYou will have the console output:\n```\nYou got new message: Hello!\n```\n\nThen dispose the subscription:\n```cs\nsub.Dispose()\n```\n\nThen raise the event:\n```cs\ne1.Raise(\"Good bye... oops!\");\n```\n\nAnd you will have no console output\n\nYou can use the using statement for your subscriptions:\n```cs\nvar handler = s =\u003e Console.WriteLine($\"You got new message: {s}\");\nusing (e1.Subscribe(handler))\n{\n    e1.Raise(\"Hello!\");\n}\ne1.Raise(\"Good bye... oops!\");\n```\n\nYou can publish your event to subscribers as ISubscriptable without access to Raise method:\n\n```cs\npublic class Publisher\n{\n    private readonly Event _somethingHappened = new Event();\n    public ISubscriptable SomethingHappened =\u003e _somethingHappened;\n}\n```\nAnd you can pass subscriptables to subscribers via their constructors or other methods:\n\n```cs\npublic class Subscriber\n{\n    private readonly IDisposable _subscription;\n\n    public Subscriber(ISubscriptable e)\n    {\n        _subscription = e.Subscribe(Handler);\n    }\n\n    public void Handler()\n    {\n        // without code\n    }\n}\n```\n\n## Thread-safety\n\nThe library provides `ConcurrentEvent` classes that guarantee that their internal state will not be broken in multi-threaded usage.\n\nThey can not fully guarantee that the event handler will not be called after the subscription is disposed.\n\nDo not run new threads in the event handlers that interact with the event! This will lead to a deadlock.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnklbdev%2Fsuby-csharp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnklbdev%2Fsuby-csharp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnklbdev%2Fsuby-csharp/lists"}