Suppose I have some process, such as downloading a file or running a big computation.
The events it fires might look like this:
{ progress: "0%" }
{ progress: "23%" }
{ progress: "78%" }
{ progress: "100%" }
{ content: "Hello. world. " }
Or perhaps:
{ progress: "0%" }
{ progress: "23%" }
{ error: "Access denied. " }
In each case, we have n
status-updates (T
) followed by either a result (S
) or an error (Throwable
):
T* ( S | Throwable )
A process is a mix of Observable<T>
and Single<S>
.
There are a few ways to model a process using the Rx primitives:
Observable<T>
andSingle<S>
Observable<Either<T, S>>
Observable<Object>
andinstanceof
Process<T, S>
withtoObservable
andtoSingle
methods- etc...
How has this been successfully modelled in the past?
Which approaches are best and when should they be used?
Aucun commentaire:
Enregistrer un commentaire