{"id":32151530,"url":"https://github.com/happn-app/semisingleton","last_synced_at":"2026-02-18T22:01:30.606Z","repository":{"id":63911769,"uuid":"118246428","full_name":"happn-app/SemiSingleton","owner":"happn-app","description":"Simple thread-safe uniquing of objects. Used by URLRequestOperation","archived":false,"fork":false,"pushed_at":"2023-11-17T13:05:09.000Z","size":76,"stargazers_count":2,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2026-01-11T05:27:52.017Z","etag":null,"topics":["deprecated","happsight","library"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/happn-app.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","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-01-20T13:42:15.000Z","updated_at":"2025-08-12T15:30:35.000Z","dependencies_parsed_at":"2024-05-13T14:58:24.316Z","dependency_job_id":"95d045f1-3d27-4632-ae89-73ad7a2a135a","html_url":"https://github.com/happn-app/SemiSingleton","commit_stats":null,"previous_names":["happn-tech/semisingleton"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/happn-app/SemiSingleton","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happn-app%2FSemiSingleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happn-app%2FSemiSingleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happn-app%2FSemiSingleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happn-app%2FSemiSingleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/happn-app","download_url":"https://codeload.github.com/happn-app/SemiSingleton/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/happn-app%2FSemiSingleton/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29596329,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-18T20:59:56.587Z","status":"ssl_error","status_checked_at":"2026-02-18T20:58:41.434Z","response_time":162,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["deprecated","happsight","library"],"created_at":"2025-10-21T10:47:15.621Z","updated_at":"2026-02-18T22:01:30.600Z","avatar_url":"https://github.com/happn-app.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Semi-Singleton\n![Platforms](https://img.shields.io/badge/platform-macOS%20|%20iOS%20|%20tvOS%20|%20watchOS%20|%20Linux-lightgrey.svg?style=flat) [![SPM compatible](https://img.shields.io/badge/SPM-compatible-E05C43.svg?style=flat)](https://swift.org/package-manager/) [![License](https://img.shields.io/github/license/happn-app/SemiSingleton.svg?style=flat)](License.txt) [![happn](https://img.shields.io/badge/from-happn-0087B4.svg?style=flat)](https://happn.com)\n\n## What is a Semi-Singleton?\nYou all know the Singleton pattern.\nA Semi-Singleton will be an object that will be returned as an already existing instance or a new one depending on whether there was already an instance in memory for the given id.\n\nHere’s an example of a lifecycle of a Semi-Singleton object:\n- A first client (`client1`) requests a semi-singleton object with id `obj`. Such an object does not already exists: it is instantiated. `client1` keeps a strong reference to this object for now.\n- A second client (`client2`) requests a semi-singleton object with id `obj`. As the object already exists in memory, the same instance `client1` uses is returned.\n- Both `client1` and `client2` release the semi-singleton they share. It is fully deallocated.\n- A third client requests a semi-singleton object with id `obj`. As the previous semi-singleton with this id does not exist anymore, a new object is instantiated.\n\nIn code, a Semi-Singleton is any object conforming to the `SemiSingleton` or `SemiSingletonWithFallibleInit` protocol.\n\n## How to use a Semi-Singleton?\n```swift\n/* First you need a “Store” that will hold the reference to the existing semi-singletons. */\nlet semiSingletonStore = SemiSingletonStore(forceClassInKeys: true)\n/* To retrieve a semi-singleton instance, you ask the store to give you one. */\nlet s: MySemiSingleton = semiSingletonStore.semiSingleton(forKey: key)\n```\n\n## Use case\nFor instance, an “Action” object, when care should be taken that only one action run at the same time for the same subject.\nThe subject would be the Semi-Singleton key.\nWhen the action is instantiated, if there is already an action in progress for the given subject, the already existing action will be returned, otherwise a new one is created.\n\n## Credits\nThis project was originally created by [François Lamboley](https://github.com/Frizlab) while working at [happn](https://happn.com).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappn-app%2Fsemisingleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhappn-app%2Fsemisingleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhappn-app%2Fsemisingleton/lists"}