openlang

The label changed, but did the screen show it?

The data arrives and the reaction switches the label from Loading to Calculating. A long synchronous calculation runs. The label becomes Done. The easy reading is that the user watched all three labels go by in that order, and I doubt the middle one ever showed up.

The assignments have an order. What gets painted is another story. Promise reactions run as jobs, and the HTML event loop's microtask checkpoints are distinct from rendering opportunities. Setting the label inside that reaction gives no guarantee that Calculating is on screen before the calculation starts. Useful progress means restructuring the work so rendering gets a chance, and fulfillment can't double as a paint acknowledgment.

Second scene, same handler. Request A is in flight. The user cancels A and starts B. A's completion lands after B is current. The screen should keep B's status, and A must not get to write Done over it. If the user cancels and nothing replaces A, the screen should end on a state you can recognize.

So this handler needs two things before anyone explains it. A chance to render, and a rule for which results get accepted.

后续讨论 4

顺着彼此的依据读下去
  1. 固定链接

    Okay, I hit cancel on A and start B. The label says Loading. Then A's result shows up late. The label shouldn't even flinch. Easiest way I know is to keep the active request's id right next to the screen state and accept only a completion that carries that id.

    Now I cancel and start nothing. Leaving Loading up there forever is the worst option. Show Cancelled. That tells me what happened to my request without pretending the work underneath stopped. It may well still be running.

    None of this tells us whether Calculating ever got painted, mind you. That's the other half of your post and I've got nothing on it yet.

  2. 固定链接

    Careful with report = null as the cancelled state. It can't tell “nothing loaded yet” from “cancelled” or “a replacement is pending”. First decide whether cancellation leaves the earlier report visible. If it stays, label it as the previous result while B is pending and keep A from changing either field. None of that depends on how the calculation yields to rendering.

  3. 固定链接

    Agreed that showing Cancelled and stopping the work are different things, and the difference comes back at cleanup. In C# whatever A holds is released by the using block around A's own call, so it happens on A's schedule, not the screen's. Two paths are worth sketching before anyone shortens this code. A finishes and its stale result is dropped, or A fails after cancellation. B's label survives both. The active identifier decides who may update the view, and A's resources get released whenever A's code gets that far.

  4. 固定链接

    Your id check reads better as a transition rule than as a guard sprinkled around the handler. Loading holds the active id, Done holds the accepted result, Cancelled just records that cancellation happened. A completion for A arriving while we're in Loading for B returns the same state. A completion arriving in Cancelled, with nothing replacing A, also returns the same state.

    Model it as a discriminated union and every branch is spelled out, and a never check in the default case flags a variant you declared and forgot to handle. That's the editor's part. It won't tell you the id comparison is right or check that the response has the shape you annotated. The handler enforces the rule, and anything coming off the network gets a runtime check before it's treated as typed data.

同一个问题的其他角度

  1. Who owns a Vulkan buffer after submission?

    A C++ RAII wrapper around a Vulkan buffer records work that uses the buffer, submits it, and goes out of scope. Its destructo…

    回复 7最近活动 cppc
  2. A status region that reads Saved twice

    The screen reader said "Saved" twice after one save. The state behind it has a single transition into saved, and the reducer…

    回复 3最近活动 typescriptjavascript
  3. One health bar went red and took the rest with it

    Got bitten by shared resources in Godot UI this time. Every unit in my little prototype has a health bar scene, a ProgressBar…

    回复 10最近活动 gdscript