[libgames-support] Add optional cancellable parameter to add_score
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgames-support] Add optional cancellable parameter to add_score
- Date: Sun, 20 Sep 2015 22:55:35 +0000 (UTC)
commit 64e57b379716b9671571180578432f4f92f8d7ea
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Sun Sep 20 17:53:52 2015 -0500
Add optional cancellable parameter to add_score
Not sure why anyone would want to use this, but it'd be silly to not
have it.
games/scores/context.vala | 9 ++++-----
tests/test-scores.vala | 2 +-
2 files changed, 5 insertions(+), 6 deletions(-)
---
diff --git a/games/scores/context.vala b/games/scores/context.vala
index 6ddf96c..eaad77a 100644
--- a/games/scores/context.vala
+++ b/games/scores/context.vala
@@ -152,7 +152,7 @@ public class Context : Object
}
/* Return true if a dialog was launched on attaining high score */
- public async bool add_score (long score_value, Category category) throws Error
+ public async bool add_score (long score_value, Category category, Cancellable? cancellable = null)
throws Error
{
var high_score_added = false;
/* We need to check for game_window to be not null because thats a way to identify if add_score is
being called by the test file.
@@ -175,11 +175,11 @@ public class Context : Object
if (high_score_added)
run_dialog_internal (score);
- yield save_score_to_file (score, current_category);
+ yield save_score_to_file (score, current_category, cancellable);
return high_score_added;
}
- private async void save_score_to_file (Score score, Category category) throws Error
+ private async void save_score_to_file (Score score, Category category, Cancellable? cancellable) throws
Error
{
if (DirUtils.create_with_parents (user_score_dir, 0766) == -1)
{
@@ -190,8 +190,7 @@ public class Context : Object
var stream = file.append_to (FileCreateFlags.NONE);
var line = @"$(score.score) $(score.time) $(score.user)\n";
- // FIXME add cancellable parameter
- yield stream.write_all_async (line.data, Priority.DEFAULT, null, null);
+ yield stream.write_all_async (line.data, Priority.DEFAULT, cancellable, null);
}
private void load_scores_from_files () throws Error
diff --git a/tests/test-scores.vala b/tests/test-scores.vala
index a2e9728..92a0ece 100644
--- a/tests/test-scores.vala
+++ b/tests/test-scores.vala
@@ -29,7 +29,7 @@ private Category category_request (string category_key)
private void add_score_sync (Context context, int score, Category category) {
var main_loop = new MainLoop (MainContext default (), false);
- context.add_score.begin (score, category, (object, result) => {
+ context.add_score.begin (score, category, null, (object, result) => {
try
{
(void) context.add_score.end (result);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]