Title: Race in the async action example? · Issue #165 · developit/unistore · GitHub
Open Graph Title: Race in the async action example? · Issue #165 · developit/unistore
X Title: Race in the async action example? · Issue #165 · developit/unistore
Description: I'm wondering about this example in the README: // Async actions can be pure async/promise functions: async getStuff(state) { let res = await fetch('/foo.json') return { stuff: await res.json() } }, I don't fully understand how you can r...
Open Graph Description: I'm wondering about this example in the README: // Async actions can be pure async/promise functions: async getStuff(state) { let res = await fetch('/foo.json') return { stuff: await res.json() } }...
X Description: I'm wondering about this example in the README: // Async actions can be pure async/promise functions: async getStuff(state) { let res = await fetch('/foo.json') return { stuff: await re...
Opengraph URL: https://github.com/developit/unistore/issues/165
X: @github
Domain: patch-diff.githubusercontent.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Race in the async action example?","articleBody":"I'm wondering about this example in the README:\r\n\r\n```\r\n // Async actions can be pure async/promise functions:\r\n async getStuff(state) {\r\n let res = await fetch('/foo.json')\r\n return { stuff: await res.json() }\r\n },\r\n```\r\n\r\nI don't fully understand how you can really support async actions like in this example.\r\n\r\nIf `getStuff()` is called twice before the first call resolves, and the two `fetch()` operations happen to finish in reverse order (because HTTP servers are unpredictable) doesn't this cause a race condition?\r\n\r\nWon't you end up with the `stuff` from the first request instead of the second?\r\n\r\nI understand (from reading [this issue](https://github.com/developit/unistore/issues/3)) that the internal call to `setState()` is defferred until the promise resolves - but I don't think that's enough to guarantee that `setState()` calls are performed in the same order the actions were invoked?\r\n\r\nFor something like an auto-complete input fetching results from the server-side, it seems like there's a good chance of this actually happening.\r\n\r\nDo I have to manually prevent races?\r\n","author":{"url":"https://github.com/mindplay-dk","@type":"Person","name":"mindplay-dk"},"datePublished":"2019-08-02T09:20:16.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/165/unistore/issues/165"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:638a7456-e2dd-ef85-a517-6e830f6980c3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8C00:1B821B:9F6123:CAFDC3:6990847A |
| html-safe-nonce | 6980206df1f9210a1d27b32cdcb33ecb91144f61f0d970b5222e2f81e01a87f5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzAwOjFCODIxQjo5RjYxMjM6Q0FGREMzOjY5OTA4NDdBIiwidmlzaXRvcl9pZCI6IjM4MDAzNzMyOTkzNDg4MDA2MzUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 694f137c03ff2bb9345777b841130ab8db90ac159597d1d8f4ac47612eb2f178 |
| hovercard-subject-tag | issue:476082758 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developit/unistore/165/issue_layout |
| twitter:image | https://opengraph.githubassets.com/03a0e437b0b5ad1ce0d2a9c3b2de05babffe1be68fe6cbec3841cde3d647f036/developit/unistore/issues/165 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/03a0e437b0b5ad1ce0d2a9c3b2de05babffe1be68fe6cbec3841cde3d647f036/developit/unistore/issues/165 |
| og:image:alt | I'm wondering about this example in the README: // Async actions can be pure async/promise functions: async getStuff(state) { let res = await fetch('/foo.json') return { stuff: await res.json() } }... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mindplay-dk |
| hostname | github.com |
| expected-hostname | github.com |
| None | 42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b |
| turbo-cache-control | no-preview |
| go-import | github.com/developit/unistore git https://github.com/developit/unistore.git |
| octolytics-dimension-user_id | 105127 |
| octolytics-dimension-user_login | developit |
| octolytics-dimension-repository_id | 113351554 |
| octolytics-dimension-repository_nwo | developit/unistore |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 113351554 |
| octolytics-dimension-repository_network_root_nwo | developit/unistore |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 3b33c5aedc9808f45bc5fcf0b1e4404cf749dac7 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width