this post is part of series, the hole series can be found in here.
this challenge was all about buffering the data on suspension period and flush it out on resume.
the idea is to suspend the observable notification for a while without loosing data.
the following diagram show the required functionality
solving this problem require some kind of buffering
and if you follow my blog you must know that when it come to
buffer and dispatch I’m usually integrating TPL Dataflow blocks.
in our case I’m using Buffer Block right in the middle between the source and the result.
the pipe-line of messaging will look like the following
source –> Buffer Block –> result
what I’m playing with is the subscription between the result to the Buffer Block.
the Buffer Block to source subscription is kept untouched while the I’m connecting
and disconnecting the subscription from the Buffer Block to the result.
whenever the Buffer Block detached from the result it keep buffering the messages,
and when it re-attached to the result all buffered messages are pushed to the result
and no data lost.
you can check the code for this extension on the next code snippet.
on line 5 I’m using Observable.Create which will encapsulate the logic (per subscription)
line 12 attaching the target to the Buffer Block (initial state)
at line 14 I’m listening the the hold / resume notification and
on the following line until line 31 I’m attaching and detaching the target from the Buffer Block
lines 33 –42 I’m attaching the Buffer Block to the source
lines 31-41 handling stream completion (flush out buffer data on completion)
lines 44-46 composing few disposable together
and that’s all
the full series can be found here