{"id":15061202,"url":"https://github.com/wokalski/vow","last_synced_at":"2025-04-10T06:37:09.791Z","repository":{"id":57152213,"uuid":"105694552","full_name":"wokalski/vow","owner":"wokalski","description":"Almost sound Promises for Bucklescript","archived":false,"fork":false,"pushed_at":"2018-11-24T07:31:53.000Z","size":1980,"stargazers_count":79,"open_issues_count":5,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-06T15:57:33.629Z","etag":null,"topics":["bucklescript","ocaml","reason"],"latest_commit_sha":null,"homepage":null,"language":"OCaml","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/wokalski.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-10-03T19:34:54.000Z","updated_at":"2022-12-12T15:34:14.000Z","dependencies_parsed_at":"2022-09-06T20:51:53.904Z","dependency_job_id":null,"html_url":"https://github.com/wokalski/vow","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/wokalski%2Fvow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wokalski%2Fvow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wokalski%2Fvow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wokalski%2Fvow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wokalski","download_url":"https://codeload.github.com/wokalski/vow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248171046,"owners_count":21059294,"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":["bucklescript","ocaml","reason"],"created_at":"2024-09-24T23:11:35.282Z","updated_at":"2025-04-10T06:37:09.739Z","avatar_url":"https://github.com/wokalski.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vow\n\n`Vow` is a tiny library which allows you to handle promises more safely in your Bucklescript application.\n\nA `Vow` can be either `handled` and `unhandled`. All promises of type `vow 'a handled` make sure that you handled Promise rejections. Thanks to that you will avoid the Uncaught promise error.\n\n## Installation\n\n```sh\nnpm install --save @wokalski/vow\n```\n\nThen add `vow` to `bs-dependencies` in your `bsconfig.json`:\n```js\n{\n  ...\n  \"bs-dependencies\": [\"@wokalski/vow\"]\n}\n```\n\n## Side effects\n\nAfter series of operations you usually want to \"consume\" a promise. `Vow.sideEffect` should be used for that.\n\nIt only accepts promises which are properly handled.\n\n## Unwrapping\n\nYou can unwrap a handled promise using `Vow.unwrap`.\n\n## Nesting vows\n\n`Js.Promise.t` is unsafe when you nest promises. i.e. `Js.Promise.t (Js.Promise.t 'a)` is unsound. In the runtime it's `Js.Promise.t`.\n\nThis is resolved with `vow`s. If you nest `vow`s they behave as expected.\n\nHowever if you put a `Js.Promise.t` inside a `vow` (which are boxed `Js.Promise.t` under the scenes) you're gonna get a `vow` of the following type:\n\n```reason\n/* in Reason syntax */\n\nvow (Js.Promise.t 'a) 'status\n```\nHowever, under the scenes it'll really be\n\n```reason\n\nvow 'a 'status\n```\n\nTherefore `vow` is not sound.\n\n## Binding\n\nIn order to use vows you have to bind to your existing APIs using `Vow.wrap`/`Vow.unsafeWrap`.\n\nIf you `unsafeWrap` a promise which does throw your code will be unsound.\n\n## Example\n\nLet's see a real world example of vows with some comments:\n\n```reason\nlet login _: Vow.Result.t authenticationState error Vow.handled =\u003e\n  /* Returns a handled Vow.Result.t */\n  Login.logIn () |\u003e\n  /* Validates the returned value. Since the vow is handled we don't need to catch*/\n  Vow.Result.flatMap (\n    fun x =\u003e\n      if x##isCancelled {\n        Vow.Result.fail LoginRequestCancelled\n      } else {\n        Vow.Result.return ()\n      }\n  ) |\u003e\n  /* Another handled Vow.Result.t */\n  Vow.Result.flatMap Login.getCurrentAccessToken () |\u003e\n  Vow.Result.map (\n    fun x =\u003e {\n      let token = x##accessToken;\n      /* This returns an unhandled Vow.Result.t.\n       * Note that the 'error types have to match\n       * Because after one error the subsequent operations\n       * Are not performed.\n       */\n      Queries.login ::token\n    }\n  ) |\u003e\n  /* Ooops, the `Queries.login` might reject.\n   * We are forced to handle it in the compile time.\n   */\n  Vow.Result.onError (fun _ =\u003e Vow.Result.fail GraphQlSignInError) |\u003e\n  Vow.Result.flatMap (\n    fun x =\u003e\n      switch x {\n      | Authenticated {token, userId} =\u003e\n        /* The promise we wrap is never rejected */\n        Vow.unsafeWrap\n          KeyChain.(\n            Js.Promise.all2 (\n              setGenericPassword username::\"userId\" password::userId service::\"userId\",\n              setGenericPassword username::\"token\" password::token service::\"token\"\n            )\n          ) |\u003e\n        Vow.map (fun _ =\u003e Vow.Result.return x)\n      | _ =\u003e Vow.Result.return x\n      }\n  );\n```\n\n## Author\n\n[@wokalski](http://twitter.com/wokalski) \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwokalski%2Fvow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwokalski%2Fvow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwokalski%2Fvow/lists"}