Remove `load` API
I propose we remove the load API, because:
- It makes the internal state machine much more complicated.
- I believe it is unnecessary because if one knows that the document is available locally, and there are no network connections open, then
requestwill have the same effect asload.
cc @alexjg
My main thought is what if you dont know the document is available locally but you don't want to wait for the network for some reason (e.g. you are writing an application which expects to be on a high latency network and you want to display a pop up telling the user that you didn't have it locally and so you're asking the network).
One alternative way to achieve this is the way the JS implementation does it, by returning a handle from request immediately and exposing some kind of status field on the handle, but I don't think that simplifies the state machine at all right?
you dont know the document is available locally but you don't want to wait for the network for some reason
How about the following:
- Add a
local_load_onlyboolean argument torequest_document. - When the storage future resolves, if it is
Ok(None)andlocal_load_onlywas true, then resolve the request with an error(or withOk(None))).
That way at that point an app embedding Spanreed could show the pop up, and ask the user whether to continue with a network request(by doing a second request_document with a false local_load_only).
This would simplify the state machine, as the above can be implemented by:
- Add the
local_load_onlytoDocState::Bootstrap. - Add a conditional here to implement 2 above.
- Remove everything related to
DocState::LoadPending
In the scenario sketched above, the second request_document with the flag set to false can still just go through the local load workflow, so nothing needs to change there.
Deterministic testing should be easy too, to the point where this could be marked as "good first issue" for an outside contributor.
What I'm wondering about the load api is, why does the load doc get an error the second time My understanding is to request the document again
@alexjg