{"id":23651512,"url":"https://github.com/athanclark/websockets-simple","last_synced_at":"2025-11-16T02:30:15.804Z","repository":{"id":56882504,"uuid":"90448717","full_name":"athanclark/websockets-simple","owner":"athanclark","description":"A simple wrapper around the websockets library.","archived":false,"fork":false,"pushed_at":"2019-10-06T19:17:58.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-25T23:02:07.900Z","etag":null,"topics":["algebraic-data-types","api","haskell","websocket"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","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":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-06T08:26:07.000Z","updated_at":"2019-10-06T19:18:00.000Z","dependencies_parsed_at":"2022-08-21T00:20:09.772Z","dependency_job_id":null,"html_url":"https://github.com/athanclark/websockets-simple","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwebsockets-simple","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwebsockets-simple/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwebsockets-simple/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwebsockets-simple/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athanclark","download_url":"https://codeload.github.com/athanclark/websockets-simple/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239611976,"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":["algebraic-data-types","api","haskell","websocket"],"created_at":"2024-12-28T16:38:08.514Z","updated_at":"2025-11-16T02:30:15.734Z","avatar_url":"https://github.com/athanclark.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# websockets-simple\n\nProvides for a slightly more composable structure for websocket apps:\n\n```haskell\ndata Input = Increment | Decrement\n  deriving (FromJSON)\n\ndata Output = Value Int\n  deriving (ToJSON)\n\nmyApp :: MonadBaseControl IO m =\u003e m (WebSocketsApp m Input Output)\nmyApp = do\n  countRef \u003c- liftIO $ newIORef 0\n  emitter \u003c- liftIO $ newIORef (Nothing :: Async ())\n\n  let killEmitter = do\n        mThread \u003c- liftIO $ readIORef emitter\n        case mThread of\n          Nothing -\u003e pure ()\n          Just thread -\u003e cancel thread\n\n  pure WebSocketsApp\n    { onOpen = \\WebSocketsAppParams{send} -\u003e\n        liftBaseWith $ \\runInBase -\u003e do\n          thread \u003c- async $ forever $ do\n            count \u003c- readIORef countRef\n            runInBase $ send $ Value count\n            threadDelay 1000000 -- every second, emit the current value\n          writeIORef emitter (Just thread)\n    , onReceive = \\WebSocketsAppParams{send,close} x -\u003e do\n        count \u003c- liftIO $\n          ( modifyIORef countRef $ case x of\n              Increment -\u003e (+ 1)\n              Decrement -\u003e (-) 1\n          ) *\u003e readIORef countRef\n        if count \u003e= 10 || count \u003c= -10\n          then close\n          else send (Value count)\n    , onClose = \\mReason -\u003e do\n        killEmitter\n        case mReason of\n          Nothing -\u003e liftIO $ writeIORef countRef 0\n          Just _ -\u003e pure ()\n    }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathanclark%2Fwebsockets-simple","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathanclark%2Fwebsockets-simple","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathanclark%2Fwebsockets-simple/lists"}