{"id":19666581,"url":"https://github.com/xaionaro-go/lockmap","last_synced_at":"2025-02-27T04:17:23.029Z","repository":{"id":252855626,"uuid":"841728587","full_name":"xaionaro-go/lockmap","owner":"xaionaro-go","description":"A map of lockers","archived":false,"fork":false,"pushed_at":"2024-09-01T17:28:18.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-10T02:44:49.605Z","etag":null,"topics":["go","golang","lock","locker","lockmap","map","variable"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xaionaro-go.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":"2024-08-12T23:47:49.000Z","updated_at":"2024-09-01T17:28:21.000Z","dependencies_parsed_at":"2024-08-13T00:52:46.378Z","dependency_job_id":null,"html_url":"https://github.com/xaionaro-go/lockmap","commit_stats":null,"previous_names":["xaionaro-go/lockmap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Flockmap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Flockmap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Flockmap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xaionaro-go%2Flockmap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xaionaro-go","download_url":"https://codeload.github.com/xaionaro-go/lockmap/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240976185,"owners_count":19887439,"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":["go","golang","lock","locker","lockmap","map","variable"],"created_at":"2024-11-11T16:28:09.980Z","updated_at":"2025-02-27T04:17:23.008Z","avatar_url":"https://github.com/xaionaro-go.png","language":"Go","readme":"# LockMap\n\n[![GoDoc](https://godoc.org/github.com/xaionaro-go/lockmap?status.svg)](https://pkg.go.dev/github.com/xaionaro-go/lockmap?tab=doc)\n\n# Motivation\n\nThis is a recurrent pattern I met in different situations. For example:\n* When we need to process an HTTP request if the result is cacheable: we want to wait one request to finish and then to copy the result to everybody who requested it.\n* When we need to allow only one goroutine to send a request out (which depends on variables).\n* etc.\n\n# Quick start\n\nSynchronous locking:\n```go\nlm := lockmap.New()\n\n...\n\n    ctx := context.Background()\n\n    unlocker := lm.Lock(ctx, \"key1\")\n    defer unlocker.Unlock(ctx, \"key1\")\n\n    // do something with key1\n```\n\nAsynchronous locking:\n```go\nlm := lockmap.New()\n\n...\n\n    ctx, cancelFn := context.WithTimeout(context.Background(), time.Second*30)\n    defer cancelFn()\n\n    unlocker, waiter := lm.LockAsync(ctx, \"key1\")\n    defer unlocker.Unlock(\"key1\")\n\n    select {\n    case \u003c-waiter.C:\n        if !unlocker.IsLocked() {\n            // reached 30sec timeout\n            return\n        }\n        // do something with key1\n    case \u003c-someOtherChan:\n        // do something else\n    }\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Flockmap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxaionaro-go%2Flockmap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxaionaro-go%2Flockmap/lists"}