{"id":24033770,"url":"https://github.com/daanv2/go-tasks","last_synced_at":"2025-02-26T05:28:04.476Z","repository":{"id":65299002,"uuid":"589354796","full_name":"DaanV2/go-tasks","owner":"DaanV2","description":"A package that allows you to easily parallelize tasks and chain them together. As well as allowing you to easily create a task that can be reused.","archived":false,"fork":false,"pushed_at":"2023-01-15T22:35:07.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-08T18:54:33.664Z","etag":null,"topics":["concurrency","go","parallel-computing","parallel-programming","tasks"],"latest_commit_sha":null,"homepage":"","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/DaanV2.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}},"created_at":"2023-01-15T22:17:42.000Z","updated_at":"2023-01-15T22:29:48.000Z","dependencies_parsed_at":"2023-01-16T09:46:19.475Z","dependency_job_id":null,"html_url":"https://github.com/DaanV2/go-tasks","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaanV2%2Fgo-tasks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaanV2%2Fgo-tasks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaanV2%2Fgo-tasks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DaanV2%2Fgo-tasks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DaanV2","download_url":"https://codeload.github.com/DaanV2/go-tasks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240797720,"owners_count":19859243,"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":["concurrency","go","parallel-computing","parallel-programming","tasks"],"created_at":"2025-01-08T18:54:44.088Z","updated_at":"2025-02-26T05:28:04.431Z","avatar_url":"https://github.com/DaanV2.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go Tasks\n\n![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/DaanV2/go-tasks)\n![GitHub release (latest by date)](https://img.shields.io/github/v/release/DaanV2/go-tasks)\n[![🐹 Golang](https://github.com/DaanV2/go-tasks/actions/workflows/go-checks.yml/badge.svg)](https://github.com/DaanV2/go-tasks/actions/workflows/go-checks.yml)\n\nA package that allows you to easily parallelize tasks and chain them together.\nAs well as allowing you to easily create a task that can be reused.\n\n## Examples\n```golang\n//State object\ntype User struct {\n\tEmail  string\n\tName   string\n\tAge    int\n\tScopes []string\n}\n\n//Example 1\n\n//Create a new task around the state object\ntask := tasks.New[User]()\ntask.\n\t//Add a tasks to the chain that will execute in order\n\tDo(RetrieveFromCache).\n\tDo(RetrieveFromDatabase).\n\t//What to do if the tasks is successful\n\tThen(UpdateCache).\n\t// What to do when the task is done\n\tFinally(func(user *User, ctx context.Context) error {\n\t\tzap.S().Infof(\"User: %+v\", user)\n\t\treturn nil\n\t}).\n\t//What to do if the tasks fails\n\tOnError(func(user *User, ctx context.Context, err error) {\n\t\tzap.S().Errorf(\"Error: %+v\", err)\n\t})\n\nerr := task.Run(context.Background())\n\n//Example 2\ntask := NewWith[User](\u0026User{Email: \"foo@bar.com\"})\ntask.\n\t// If the first function returns an error, run the second function.\n\tDo(IfElse(RetrieveFromCache, RetrieveFromDatabase)).\n\tThen(UpdateCache)\n\n//Example 3\ntask := tasks.New[User]()\ntask.\n\tDo(RetrieveFromCache).\n\tDo(RetrieveFromDatabase).\n\tThen(UpdateCache).\n\tFinally(func(user *User, ctx context.Context) error {\n\t\tzap.S().Infof(\"User: %+v\", user)\n\t\treturn nil\n\t}).\n\tOnError(func(user *User, ctx context.Context, err error) {\n\t\tzap.S().Errorf(\"Error: %+v\", err)\n\t})\n\nnewTask := task.CopyFor(\u0026User{Email: \"foo@bar.com\"})\n\n//Example 4\nnext := task.Chain(New[User]())\nnext.\n\tDo(ValidateUser).\n\tFinally(func(user *User, ctx context.Context) error {\n\t\terr := ctx.Value(\"error\").(error)\n\t\tif err != nil {\n\t\t\tzap.S().Errorf(\"Error: %+v\", err)\n\t\t}\n\n\t\treturn nil\n\t})\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaanv2%2Fgo-tasks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaanv2%2Fgo-tasks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaanv2%2Fgo-tasks/lists"}