{"id":22332730,"url":"https://github.com/xgfone/go-taskflow","last_synced_at":"2025-07-29T19:33:23.922Z","repository":{"id":40680382,"uuid":"56246024","full_name":"xgfone/go-taskflow","owner":"xgfone","description":"A task flow in Go, you can use it to do and undo.","archived":false,"fork":false,"pushed_at":"2022-09-13T09:06:41.000Z","size":26,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-30T20:49:13.439Z","etag":null,"topics":["line-taskflow","task-flow","taskflow"],"latest_commit_sha":null,"homepage":"","language":"Go","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/xgfone.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":"2016-04-14T14:50:34.000Z","updated_at":"2024-08-10T13:36:54.000Z","dependencies_parsed_at":"2022-09-26T18:31:29.639Z","dependency_job_id":null,"html_url":"https://github.com/xgfone/go-taskflow","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-taskflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-taskflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-taskflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xgfone%2Fgo-taskflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xgfone","download_url":"https://codeload.github.com/xgfone/go-taskflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228042049,"owners_count":17860360,"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":["line-taskflow","task-flow","taskflow"],"created_at":"2024-12-04T04:19:31.103Z","updated_at":"2024-12-04T04:19:31.819Z","avatar_url":"https://github.com/xgfone.png","language":"Go","readme":"# go-taskflow [![Build Status](https://github.com/xgfone/go-taskflow/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-taskflow/actions/workflows/go.yml) [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-taskflow)](https://pkg.go.dev/github.com/xgfone/go-taskflow) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/go-taskflow/master/LICENSE)\n\nA task flow supporting `Go1.7+`, you can use it to do and undo the tasks.\n\n## Installation\n```shell\n$ go get -u github.com/xgfone/go-taskflow\n```\n\n## Example\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/xgfone/go-taskflow\"\n)\n\nfunc logf(msg string, args ...interface{}) error {\n\tfmt.Printf(msg+\"\\n\", args...)\n\treturn nil\n}\n\nfunc do(n string) taskflow.TaskFunc {\n\treturn func(context.Context) error { return logf(\"do the task '%s'\", n) }\n}\n\nfunc undo(n string) taskflow.TaskFunc {\n\treturn func(context.Context) error { return logf(\"undo the task '%s'\", n) }\n}\n\nfunc failDo(n string) taskflow.TaskFunc {\n\treturn func(context.Context) error {\n\t\tlogf(\"do the task '%s'\", n)\n\t\treturn fmt.Errorf(\"failure\")\n\t}\n}\n\nfunc newTask(n string) taskflow.Task {\n\treturn taskflow.NewTask(n, do(n), undo(n))\n}\n\nfunc newFailTask(n string) taskflow.Task {\n\treturn taskflow.NewTask(n, failDo(n), undo(n))\n}\n\nfunc main() {\n\tflow1 := taskflow.NewLineFlow(\"lineflow1\")\n\tflow1.\n\t\tAddTasks(\n\t\t\tnewTask(\"task1\"),\n\t\t\tnewTask(\"task2\"),\n\t\t\tnewTask(\"task3\"),\n\t\t)\n\n\tflow2 := taskflow.NewLineFlow(\"lineflow2\")\n\tflow2.\n\t\tAddTasks(\n\t\t\tnewTask(\"task4\"),\n\t\t\tnewFailTask(\"task5\"),\n\t\t\tnewTask(\"task6\"),\n\t\t)\n\n\tflow3 := taskflow.NewLineFlow(\"lineflow3\")\n\tflow3.AddTask(\"task7\", do(\"task7\"), undo(\"task7\")) // Use task functions\n\tflow3.\n\t\tAddTasks(\n\t\t\tflow1,\n\t\t\tnewTask(\"task8\"),\n\t\t\tflow2,\n\t\t\tnewTask(\"task9\"),\n\t\t)\n\n\terr := flow3.Do(context.Background())\n\tfmt.Println(err)\n\n\t// Output:\n\t// do the task 'task7'\n\t// do the task 'task1'\n\t// do the task 'task2'\n\t// do the task 'task3'\n\t// do the task 'task8'\n\t// do the task 'task4'\n\t// do the task 'task5'\n\t// undo the task 'task4'\n\t// undo the task 'task8'\n\t// undo the task 'task3'\n\t// undo the task 'task2'\n\t// undo the task 'task1'\n\t// undo the task 'task7'\n\t// FlowError(name=lineflow3, errs=[FlowError(name=lineflow2, errs=[TaskError(name=task5, doerr=failure)])])\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-taskflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxgfone%2Fgo-taskflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxgfone%2Fgo-taskflow/lists"}