{"id":13411558,"url":"https://github.com/cocoonspace/fsm","last_synced_at":"2025-03-14T17:30:56.724Z","repository":{"id":46440602,"uuid":"415873633","full_name":"cocoonspace/fsm","owner":"cocoonspace","description":"Finite State Machine package in Go","archived":false,"fork":false,"pushed_at":"2023-02-08T13:23:22.000Z","size":17,"stargazers_count":59,"open_issues_count":3,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-07-31T20:48:00.773Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cocoonspace.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":"2021-10-11T10:12:51.000Z","updated_at":"2024-06-14T22:35:05.000Z","dependencies_parsed_at":"2024-06-19T02:53:02.758Z","dependency_job_id":"dc5c919c-7790-475f-af25-f412a90b487e","html_url":"https://github.com/cocoonspace/fsm","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoonspace%2Ffsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoonspace%2Ffsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoonspace%2Ffsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cocoonspace%2Ffsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cocoonspace","download_url":"https://codeload.github.com/cocoonspace/fsm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243618635,"owners_count":20320269,"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":[],"created_at":"2024-07-30T20:01:14.534Z","updated_at":"2025-03-14T17:30:56.415Z","avatar_url":"https://github.com/cocoonspace.png","language":"Go","readme":"# fsm [![PkgGoDev](https://pkg.go.dev/badge/github.com/cocoonspace/fsm)](https://pkg.go.dev/github.com/cocoonspace/fsm) [![Build Status](https://app.travis-ci.com/cocoonspace/fsm.svg?branch=master)](https://app.travis-ci.com/cocoonspace/fsm) [![Coverage Status](https://coveralls.io/repos/github/cocoonspace/fsm/badge.svg?branch=master)](https://coveralls.io/github/cocoonspace/fsm?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/cocoonspace/fsm)](https://goreportcard.com/report/github.com/cocoonspace/fsm)\n\nPackage fsm allows you to add [finite-state machines](https://en.wikipedia.org/wiki/Finite-state_machine) to your Go code.\n\nStates and Events are defined as int consts:\n\n```go\nconst (\n    StateFoo fsm.State = iota\n    StateBar\n)\n\nconst (\n    EventFoo fsm.Event = iota\n    EventBar\n)\n\nf := fsm.New(StateFoo)\nf.Transition(\n    fsm.On(EventFoo), fsm.Src(StateFoo),\n    fsm.Dst(StateBar),\n)\n```\n\nYou can have custom checks or actions:\n\n```go\nf.Transition(\n    fsm.Src(StateFoo), fsm.Check(func () bool {\n        // check something\n    }),\n    fsm.Call(func () {\n        // do something\n    }),\n)\n```\n\nTransitions can be triggered the second time an event occurs:\n\n```go\nf.Transition(\n    fsm.On(EventFoo), fsm.Src(StateFoo), fsm.Times(2),\n    fsm.Dst(StateBar),\n)\n```\n\nFunctions can be called when entering or leaving a state:\n\n```go\nf.EnterState(StateFoo, func() {\n    // do something\t\n})\nf.Enter(func(state fsm.State) {\n    // do something\t\n})\nf.ExitState(StateFoo, func() {\n    // do something\t\n})\nf.Exit(func(state fsm.State) {\n    // do something\t\n})\n```\n\n## Performance\n\nThis package is much faster and does a lot less allocations than github.com/looplab/fsm:\n\n```\nBenchmarkCocoonSpaceFSM-12    \t29371851\t        40.32 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkLooplabFSM-12        \t 2438946\t       487.8 ns/op\t     320 B/op\t       4 allocs/op\n```\n\n(benchmark data is for two executed transitions)\n\nBenchmark information on https://github.com/cocoonspace/fsm-bench\n\n## Installation\n\ngo get github.com/cocoonspace/fsm\n\n## Contribution guidelines\n\nContributions are welcome, as long as:\n\n* unit tests \u0026 comments are included,\n* no external package is used.\n\n## License\n\nMIT - See LICENSE\n","funding_links":[],"categories":["数据结构与算法","Data Structures","Data Structures and Algorithms","Uncategorized","Generators","Data Integration Frameworks"],"sub_categories":["杂项数据结构和算法","Advanced Console UIs","Standard CLI","Miscellaneous Data Structures and Algorithms"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocoonspace%2Ffsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcocoonspace%2Ffsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcocoonspace%2Ffsm/lists"}