[blam] ItemList: change save semantics not to restart the timer
- From: Carlos Martín Nieto <cmartin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [blam] ItemList: change save semantics not to restart the timer
- Date: Sat, 15 Jun 2013 13:29:26 +0000 (UTC)
commit 62f28885734dc3b7eb965414a8e1169a01ebf74d
Author: Carlos Martín Nieto <cmn dwim me>
Date: Sat Jun 15 15:25:19 2013 +0200
ItemList: change save semantics not to restart the timer
Switch the databse save semantics from restarting the timer every time
something is changed to batching updates in five-minute blocks. If the
delayed task already exists, we let it write out our updates as well.
src/ChannelCollection.cs | 17 +++++------------
1 files changed, 5 insertions(+), 12 deletions(-)
---
diff --git a/src/ChannelCollection.cs b/src/ChannelCollection.cs
index fb3965f..ae7ea97 100644
--- a/src/ChannelCollection.cs
+++ b/src/ChannelCollection.cs
@@ -31,8 +31,6 @@ namespace Imendio.Blam {
private Object clock = new Object();
Task DelayedWrite;
- CancellationTokenSource DelayedWriteCancellation = new CancellationTokenSource();
-
private static uint WRITE_TIMEOUT = 5 * 60 * 1000; // Every 5 minutes
@@ -263,20 +261,15 @@ namespace Imendio.Blam {
});
}
- // TODO: this keeps the old semantics of restarting the timer, but we
- // might want to simply see if we should start one and not do anything
- // if there's already a task enqueued.
- private void MarkAsDirty()
+
+ void MarkAsDirty()
{
if (DelayedWrite != null && !DelayedWrite.IsCompleted)
- DelayedWriteCancellation.Cancel();
+ return;
- DelayedWriteCancellation = new CancellationTokenSource();
- DelayedWrite = Task.Delay(TimeSpan.FromMilliseconds(WRITE_TIMEOUT),
DelayedWriteCancellation.Token);
+ DelayedWrite = Task.Delay(TimeSpan.FromMilliseconds(WRITE_TIMEOUT));
DelayedWrite.ContinueWith(task => {
- if (task.IsCanceled)
- return;
-
+ Console.WriteLine("writing data to disc");
SaveToFile();
ItemStore.Save();
});
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]