{"id":23651525,"url":"https://github.com/athanclark/elm-threading","last_synced_at":"2025-11-16T02:30:15.469Z","repository":{"id":57674824,"uuid":"61423740","full_name":"athanclark/elm-threading","owner":"athanclark","description":"A simple threading patch for elm ports","archived":false,"fork":false,"pushed_at":"2016-06-25T03:13:14.000Z","size":4,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T16:38:04.255Z","etag":null,"topics":["elm","threading"],"latest_commit_sha":null,"homepage":null,"language":"Elm","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/athanclark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-18T08:07:29.000Z","updated_at":"2018-11-27T20:56:07.000Z","dependencies_parsed_at":"2022-09-02T15:01:32.781Z","dependency_job_id":null,"html_url":"https://github.com/athanclark/elm-threading","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/athanclark%2Felm-threading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Felm-threading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Felm-threading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Felm-threading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athanclark","download_url":"https://codeload.github.com/athanclark/elm-threading/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239611991,"owners_count":19668272,"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":["elm","threading"],"created_at":"2024-12-28T16:38:12.912Z","updated_at":"2025-11-16T02:30:15.416Z","avatar_url":"https://github.com/athanclark.png","language":"Elm","funding_links":[],"categories":[],"sub_categories":[],"readme":"# elm-threading\n\nA simple method for managing asynchronous ports that may be flooded\nwith invocations:\n\n```elm\n-- a simple hashing module\nmodule Hash exposing (..)\n\nimport Threading\nimport Task\n\n\ntype alias Hashed = String\n\nport makeHash : String -\u003e Cmd a\nport madeHash : (Hashed -\u003e a) -\u003e Sub a\n\n\ntype Msg a\n  = ThreadingMsg (Threading.Msg String Hashed Msg)\n  | HashThis String (Hashed -\u003e Cmd a)\n\ntype alias Model a =\n  { threading : Threading.Model Hashed (Msg a)\n  }\n  \ninit : (Model a, Cmd (Msg a))\ninit = ({ threading = Threading.init }, Cmd.none )\n\nupdate : Msg a -\u003e Model a -\u003e (Model a, Cmd a)\nupdate action model =\n  case action of\n    ThreadingMsg a -\u003e\n      let (newThreading, threadingCmd) =\n            Threading.update makeHash a model.threading\n      in  ( { model | threading = newThreading }\n          , Cmd.map (\\r -\u003e case r of\n                             Err a -\u003e ThreadingMsg a\n                             Ok a  -\u003e a) threadingCmd\n          )\n    HashThis toHash whenComplete -\u003e\n      ( model\n      , Task.perform Debug.crash ThreadingMsg\n          \u003c| Task.succeed \u003c| Threading.Call toHash whenComplete\n      )\n\nsubscriptions : Sub (Msg a)\nsubscriptions = Sub.map ThreadingMsg\n             \u003c| Threading.subscriptions madeHash\n```\n\nBam! Continuation-style passing for javascript ports. Note that\nwe leave `a` here - we still need the user of this module to pass\ntheir \"handler\" for when the port finishes, but that's okay by\nmy book. If you have serious complaints, you should use sticks\nand rocks instead of your computer.\n\n\u003e It may be easier to use\n\u003e [Shmookey's Cmd.Extra](http://package.elm-lang.org/packages/shmookey/cmd-extra/1.0.0/Cmd-Extra)\n\u003e instead of constantly doing `Task.perform Debug.crash identity \u003c\u003c Task.succeed`\n\u003e all over teh place\n\n```js\napp.ports.makeHash.subscribe(function(threadedInput) {\n  var threadedOutput = {\n    threadId = threadedInput.threadId,\n    payload  = hash(threadedInput.payload) // something async or w/e\n  };\n  app.ports.madeHash.send(threadedOutput);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathanclark%2Felm-threading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathanclark%2Felm-threading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathanclark%2Felm-threading/lists"}