{"id":31559432,"url":"https://github.com/amrsaber/go-blocking-dequeue","last_synced_at":"2025-10-05T01:38:37.473Z","repository":{"id":45826902,"uuid":"498127503","full_name":"AmrSaber/go-blocking-dequeue","owner":"AmrSaber","description":"Thread safe, blocking, generic dequeue data structure for Go","archived":false,"fork":false,"pushed_at":"2022-06-06T15:14:30.000Z","size":57,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-29T09:17:31.527Z","etag":null,"topics":["blocking-queue","blocking-stack","dequeue","generic","go","golang","infinite","queue","stack","thread-safe","thread-safe-queue","thread-safe-stack"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/AmrSaber/go-blocking-dequeue","language":"Go","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/AmrSaber.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-30T23:46:36.000Z","updated_at":"2023-03-08T04:13:32.000Z","dependencies_parsed_at":"2022-09-04T19:11:18.656Z","dependency_job_id":null,"html_url":"https://github.com/AmrSaber/go-blocking-dequeue","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/AmrSaber/go-blocking-dequeue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrSaber%2Fgo-blocking-dequeue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrSaber%2Fgo-blocking-dequeue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrSaber%2Fgo-blocking-dequeue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrSaber%2Fgo-blocking-dequeue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AmrSaber","download_url":"https://codeload.github.com/AmrSaber/go-blocking-dequeue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AmrSaber%2Fgo-blocking-dequeue/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278399622,"owners_count":25980329,"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","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","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":["blocking-queue","blocking-stack","dequeue","generic","go","golang","infinite","queue","stack","thread-safe","thread-safe-queue","thread-safe-stack"],"created_at":"2025-10-05T01:38:28.074Z","updated_at":"2025-10-05T01:38:37.465Z","avatar_url":"https://github.com/AmrSaber.png","language":"Go","readme":"# Blocking Dequeue\n\n![Tests status](https://github.com/AmrSaber/go-blocking-dequeue/actions/workflows/tests.yaml/badge.svg?branch=master)\n![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/AmrSaber/go-blocking-dequeue?color=blue\u0026display_name=tag\u0026sort=semver)\n![GitHub license](https://img.shields.io/github/license/AmrSaber/go-blocking-dequeue)\n\nThis package (repo) provides an implementation of a thread-safe, blocking, generic dequeue that can be used as FIFO or LIFO or a hybrid between the 2.\n\n## Installation\n\nTo install this package, you will need to setup your go workspace first. Also this package requires go **v1.18** or later.\n\n1. To install the package run the following command:\n\n   ```bash\n   go get github.com/AmrSaber/go-blocking-dequeue\n   ```\n\n2. To import the package:\n\n   ```go\n   import \"github.com/AmrSaber/go-blocking-dequeue\"\n   ```\n\n3. Use the package in code using `blocking_dequeue` module (see usage below).\n\n## Usage\n\n### Initialization\n\nTo create a new dequeue use `blocking_dequeue.NewBlockingDequeue` function as follows:\n\n```go\n// Integers dequeue\nbuffer := make([]int, 10)\nintegersDequeue := blocking_dequeue.NewBlockingDequeue(buffer)\nintegersDequeue.PushBack(10)\n\n// Strings dequeue\nbuffer := make([]string, 10)\nstringsDequeue := blocking_dequeue.NewBlockingDequeue(buffer)\nstringsDequeue.PushBack(\"hello\")\n\ntype User struct {\n  Username string\n  Age      int\n}\n\n// Dequeue of custom type\nbuffer := make([]User, 10)\nusersDequeue := blocking_dequeue.NewBlockingDequeue(buffer)\nusersDequeue.PushBack(User{ \"Amr\", 25 })\n\n// Pointer dequeue\nbuffer := make([]*User, 10)\nusersPtrDequeue := blocking_dequeue.NewBlockingDequeue(buffer)\nusersPtrDequeue.PushBack(\u0026User{ \"Amr\", 25 })\n```\n\nThe dequeue is implemented using generics, so it can hold any datatype, just create a buffer with the desired datatype and pass it to the creation function.\n\n### Capacity\n\nThe capacity of the dequeue is the length of the provided buffer.\n\n### Usage as Queue\n\n```go\nbuffer := make([]int, 10)\ndq := blocking_dequeue.NewBlockingDequeue(buffer)\n\ndq.PushBack(1) // Pushed to the end of the dequeue\ndq.PushBack(2) // Pushed to the end of the dequeue\ndq.PushBack(3) // Pushed to the end of the dequeue\n\ndq.PopFront() // Pops from the top, returns 1\ndq.PopFront() // Pops from the top, returns 2\ndq.PopFront() // Pops from the top, returns 3\n```\n\n### Usage as Stack\n\n```go\nbuffer := make([]int, 10)\ndq := blocking_dequeue.NewBlockingDequeue(buffer)\n\ndq.PushFront(1) // Pushed to the start of the dequeue\ndq.PushFront(2) // Pushed to the start of the dequeue\ndq.PushFront(3) // Pushed to the start of the dequeue\n\ndq.PopFront() // Pops from the top, returns 3\ndq.PopFront() // Pops from the top, returns 2\ndq.PopFront() // Pops from the top, returns 1\n```\n\n## API Documentation\n\nThe package itself exposes 1 function `NewBlockingQueue` that is used to create a new dequeue and return a pointer to it.\n\nThe dequeue itself exposes the following methods:\n\n- `PushFront`, `PushBack`\n- `PopFront`, `PopBack`\n- `PeekFront`, `PeekBack`\n- `Size`, `IsEmpty`, `IsFull`\n\nThe detailed documentation can be found at the related [go packages page](https://pkg.go.dev/github.com/AmrSaber/go-blocking-dequeue#section-documentation).\n\n## Limitations and Drawbacks\n\nThis dequeue is implemented using ring (or circular) buffer so all of the operations are done in O(1) time complexity.\n\nHowever, due to the thread-safe nature, and all the lock/unlock/wait/signal logic, it's expected to be a bit slower than plain ring buffer. If you intend to use this dequeue in a single threaded context (where only a single goroutine will have access to it) it's advised to use plain circular buffer or the built-in `container/list` instead.\n\nIf you intend to use it as a limited capacity queue to communicate between goroutines, it would be better to use built-in channels with buffer, so instead of\n\n```go\nbuffer := make([]int, 10)\ndq := blocking_dequeue.NewBlockingDequeue(buffer)\n\n// Push to queue\ndq.PushBack(1)\n\n// Pop from queue\ndq.PopFront()\n```\n\nYou better use\n\n```go\nch := make(chan int, 10)\n\n// Push to queue\nch \u003c- 1\n\n// Pop from queue\n\u003c- ch\n```\n\nThat is unless you need access the other provided methods, such as `Peek` variations, `Size`, `IsFull`, and so on...\n\n## Benchmarking\n\nNo benchmarking against plain ring buffer or the built-in `container/list` nor channels yet. But it's in the plan.\n\n## Contribution\n\nIf you find a bug, you are welcome to [create a ticket on github](https://github.com/AmrSaber/go-blocking-dequeue/issues) or create a PR with the fix directly mentioning in the description of the PR what is the problem and how your PR fixes it.\n\nIf you want to suggest a feature (even if you have no idea how it will be implemented) feel free to [open a ticket with it](https://github.com/AmrSaber/go-blocking-dequeue/issues).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famrsaber%2Fgo-blocking-dequeue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famrsaber%2Fgo-blocking-dequeue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famrsaber%2Fgo-blocking-dequeue/lists"}