{"id":15954796,"url":"https://github.com/tembleking/spawn","last_synced_at":"2026-06-19T16:32:29.238Z","repository":{"id":220550242,"uuid":"751937302","full_name":"tembleking/spawn","owner":"tembleking","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-05T08:59:30.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T06:43:42.955Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tembleking.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-02-02T16:49:19.000Z","updated_at":"2024-02-02T16:54:30.000Z","dependencies_parsed_at":"2024-06-21T14:26:05.083Z","dependency_job_id":null,"html_url":"https://github.com/tembleking/spawn","commit_stats":null,"previous_names":["tembleking/spawn"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/tembleking/spawn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tembleking%2Fspawn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tembleking%2Fspawn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tembleking%2Fspawn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tembleking%2Fspawn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tembleking","download_url":"https://codeload.github.com/tembleking/spawn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tembleking%2Fspawn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34539729,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"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":[],"created_at":"2024-10-07T13:19:55.264Z","updated_at":"2026-06-19T16:32:29.211Z","avatar_url":"https://github.com/tembleking.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spawn\n\n## Overview\n\nSpawn is a lightweight Go package designed to simplify handling of concurrent tasks by providing a simple and intuitive way to spawn goroutines and wait for their completion. It offers a JoinHandle type that represents a handle to a spawned task, allowing you to wait for its completion, retrieve the result, and check if it has finished.\nInstallation\n\nTo use spawn in your Go project, simply import it using go get:\n\n```bash\ngo get github.com/tembleking/spawn\n```\n\n## Usage\n\n### Spawning a Task\n\nTo spawn a task, use the `Func` function, passing in the function that you want to execute concurrently. This function returns a `JoinHandle` representing the spawned task.\n\n```go\njoinHandle := spawn.Func(func() (result T, err error) {\n    // Your concurrent task logic here\n    return result, err\n})\n```\n\n### Waiting for Task Completion\n\nYou can wait for the spawned task to complete using the `Wait` or `WaitCtx` methods of the `JoinHandle`.\n\n```go\nresult, err := joinHandle.Wait() // Waits indefinitely for task completion\n```\n\nor\n\n```go\nresult, err := joinHandle.WaitCtx(context.Background()) // Wait with context\n```\n\n### Checking Task Completion\n\nYou can also check whether the task has finished executing using the `IsFinished` method.\n\n```go\nif handle.IsFinished() {\n    // Task has finished\n} else {\n    // Task is still running\n}\n```\n\n## Examples\n\n### Basic Example\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/tembleking/spawn\"\n)\n\nfunc main() {\n\t// Spawn a task\n\thandle := spawn.Func(func() (result int, err error) {\n\t\ttime.Sleep(10 * time.Millisecond)\n\t\treturn 42, nil\n\t})\n\n\t// Wait for the task to complete\n\tresult, err := handle.Wait()\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t} else {\n\t\tfmt.Println(\"Result:\", result)\n\t}\n}\n```\n\n### Example with function that only returns error\n\n```go\npackage main\n\nimport (\n\t\"errors\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/tembleking/spawn\"\n)\n\nfunc main() {\n\tfuncThatReturnsError := func() error {\n\t\ttime.Sleep(10 * time.Millisecond)\n\t\treturn errors.New(\"some error\")\n\t}\n\n\tjoinHandle := spawn.Func(func() (struct{}, error) {\n\t\treturn struct{}{}, funcThatReturnsError()\n\t})\n\n\t_, err := joinHandle.Wait()\n\tif err != nil {\n\t\tfmt.Println(\"Error:\", err)\n\t}\n}\n```\n\n### Example with function that returns nothing\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"time\"\n\n    \"github.com/tembleking/spawn\"\n)\n\nfunc main() {\n\tfuncThatReturnsNothing := func() {\n\t\ttime.Sleep(10 * time.Millisecond)\n\t}\n\n\tjoinHandle := spawn.Func(func() (struct{}, error) {\n\t\tfuncThatReturnsNothing()\n\t\treturn struct{}{}, nil\n\t})\n\n\t_, _ = joinHandle.Wait()\n\tfmt.Println(\"Task completed\")\n}\n```\n\n\n## Contributing\n\nContributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on GitHub.\n\n## License\n\nThis package is licensed under the LGPL-3.0 License. See the [LICENSE](LICENSE) file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftembleking%2Fspawn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftembleking%2Fspawn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftembleking%2Fspawn/lists"}