• SavvyWolf@pawb.social
    link
    fedilink
    English
    arrow-up
    30
    ·
    9 months ago

    I had a visceral reaction to this because obviously the wish count should be decremented before the wish takes place. Even though I can’t think up a convincing technical argument for it.

    • balsoft@lemmy.ml
      link
      fedilink
      arrow-up
      14
      ·
      9 months ago

      If there’s parallelism/async involved, then there definitely is an argument to decrement first, execute later. Otherwise you could make a wish for the genie to just wait for an hour and then make as many wishes as you want within that hour.

      • Brekky@lemmy.world
        link
        fedilink
        arrow-up
        3
        ·
        9 months ago

        But how can you decrement a future dated wish, since you can’t guarantee nothing will happen that prevents the genies ability from executing said wish? E.g. i mean like telling the Genie to do something 5 days from now, not your example which would begin immediately after making said wish.

        • balsoft@lemmy.ml
          link
          fedilink
          arrow-up
          4
          ·
          9 months ago

          You decrement the wish counter first, execute the action (which includes waiting those 5 days), and if it fails you increment the counter back. Something like this:

          wishes = wishes - 1;
          executeWish(wish).unwrap_or_else(|_| { wishes = wishes + 1; })?
          

          This way if the action fails in the future, you get a wish back and can ask something else.

    • Skullgrid@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      9 months ago

      I had a visceral reaction to this because obviously the wish count should be decremented before the wish takes place.

      Why? Shouldn’t you decrement the limited resource the user has access to in case the thing you are doing fails?

    • tyler@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      9 months ago

      You’d need a check to make sure they don’t wish for something not allowed (like more wishes).