{"id":20051634,"url":"https://github.com/ring-clojure/ring-websocket-async","last_synced_at":"2025-05-05T11:31:49.179Z","repository":{"id":195812452,"uuid":"693728087","full_name":"ring-clojure/ring-websocket-async","owner":"ring-clojure","description":"Library for using core.async with Ring's websocket API","archived":false,"fork":false,"pushed_at":"2024-05-04T12:43:09.000Z","size":28,"stargazers_count":10,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-10T10:56:46.598Z","etag":null,"topics":["clojure","ring-clojure","websockets"],"latest_commit_sha":null,"homepage":"","language":"Clojure","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/ring-clojure.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}},"created_at":"2023-09-19T15:37:23.000Z","updated_at":"2024-07-04T18:16:20.000Z","dependencies_parsed_at":"2023-10-21T16:23:34.180Z","dependency_job_id":null,"html_url":"https://github.com/ring-clojure/ring-websocket-async","commit_stats":null,"previous_names":["ring-clojure/ring-websocket-async"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ring-clojure%2Fring-websocket-async","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ring-clojure%2Fring-websocket-async/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ring-clojure%2Fring-websocket-async/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ring-clojure%2Fring-websocket-async/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ring-clojure","download_url":"https://codeload.github.com/ring-clojure/ring-websocket-async/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224443947,"owners_count":17312127,"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":["clojure","ring-clojure","websockets"],"created_at":"2024-11-13T12:05:02.460Z","updated_at":"2024-11-13T12:05:03.120Z","avatar_url":"https://github.com/ring-clojure.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ring-Websocket-Async [![Build Status](https://github.com/ring-clojure/ring-websocket-async/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/ring-clojure/ring-websocket-async/actions/workflows/test.yml)\n\nA Clojure library for using [core.async][] with [Ring's][] websocket API\n(currently in beta testing).\n\n[core.async]: https://github.com/clojure/core.async\n[ring's]: https://github.com/ring-clojure/ring\n\n## Installation\n\nAdd the following dependency to your deps.edn file:\n\n    org.ring-clojure/ring-websocket-async {:mvn/version \"0.2.0\"}\n\nOr to your Leiningen project file:\n\n    [org.ring-clojure/ring-websocket-async \"0.2.0\"]\n\n## Breaking Changes\n\nIn 0.1.0 the `go-websocket` block would automatically close the\nWebSocket after it completes. In 0.2.0 this was removed, as it prevented\neasy use of functions like `clojure.core.async/pipe`, which have their\nown internal `go` blocks.\n\n## Usage\n\nThe most convenient way to get started is to use the `go-websocket`\nmacro. Here's an example that echos any message received back to the\nclient:\n\n```clojure\n(require '[clojure.core.async :as a :refer [\u003c! \u003e!]]\n         '[ring.websocket.async :as wsa])\n\n(defn echo-websocket-handler [request]\n  (wsa/go-websocket [in out err]\n    (loop []\n      (when-let [mesg (\u003c! in)]\n        (\u003e! out mesg)\n        (recur)))))\n```\n\nThe macro sets three binding variables:\n\n* `in`  - the input channel\n* `out` - the output channel\n* `err` - the error channel\n\nThen executes its body in a core.async `go` block. If the WebSocket is\nclosed by either the client or the server, the associated channels will\nalso be closed.\n\nA Ring websocket response will be returned by the macro, so you can\ndirectly return it from the handler.\n\nThe error channel may be omitted. In this case, any errors with the\nwebsocket protocol will close the connection with a 1011 unexpected\nserver error message.\n\nTo close the connection from the server with a specific error code of\nyour choice, you can use the `closed` function to send a special message\nto the output channel:\n\n```clojure\n(defn closes-with-error [request]\n  (wsa/go-websocket [in out err]\n    (\u003e! out (wsa/closed 1001 \"Gone Away\"))))\n```\n\nIf you want more control, you can use the lower-level\n`websocket-listener` function. The following handler example is\nequivalent to the one using the `go-websocket` macro:\n\n```clojure\n(defn echo-websocket-handler [request]\n  (let [in  (a/chan)\n        out (a/chan)\n        err (a/chan)]\n    (go (try\n          (loop []\n            (when-let [mesg (\u003c! in)]\n              (\u003e! out mesg)\n              (recur)))\n          (finally\n            (a/close! out))))  ;; closes the websocket\n    {:ring.websocket/listener (websocket-listener in out err)}))\n```\n\n## License\n\nCopyright © 2024 James Reeves\n\nReleased under the MIT license.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fring-clojure%2Fring-websocket-async","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fring-clojure%2Fring-websocket-async","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fring-clojure%2Fring-websocket-async/lists"}