<commit_before>﻿//-----------------------------------------------------------------------
// <copyright file="TimerGroup.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace TimerSample
{
    using System;
    using System.Collections.Generic;
    using System.Threading;

    public sealed class TimerGroup : IDisposable
    {
        private readonly Dictionary<Guid, PeriodicAction> actions;

        public TimerGroup()
        {
            this.actions = new Dictionary<Guid, PeriodicAction>();
        }

        public Guid Add(TimeSpan interval, Action action)
        {
            Guid id = Guid.NewGuid();
            this.actions.Add(id, new PeriodicAction(interval, action));
            return id;
        }

        public void Remove(Guid id)
        {
            PeriodicAction action;
            if (this.actions.TryGetValue(id, out action))
            {
                using (action)
                {
                    this.actions.Remove(id);
                }
            }
        }

        public void Dispose()
        {<commit_msg>Add factory function to create actions<commit_after>﻿//-----------------------------------------------------------------------
// <copyright file="TimerGroup.cs" company="<NAME>">
// Copyright (c) <NAME>. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace TimerSample
{
    using System;
    using System.Collections.Generic;
    using System.Threading;

    public sealed class TimerGroup : IDisposable
    {
        private readonly Dictionary<Guid, PeriodicAction> actions;

        public TimerGroup()
        {
            this.actions = new Dictionary<Guid, PeriodicAction>();
            this.Create = (i, a) => new PeriodicAction(i, a);
        }

        private Func<TimeSpan, Action, PeriodicAction> Create { get; set; }

        public Guid Add(TimeSpan interval, Action action)
        {
            Guid id = Guid.NewGuid();
            this.actions.Add(id, this.Create(interval, action));
            return id;
        }

        public void Remove(Guid id)
        {
            PeriodicAction action;
            if (this.actions.TryGetValue(id, out action))
            {
                using (action)
                {
                    this.actions.Remove(id);
                }
            }
        }

        public void Dispose()
        {
{'fraction_non_alphanumeric': 0.20404922588328703, 'fraction_numerical': 0.0, 'mean_word_length': 1.247992863514719, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1789269', 'n_tokens_mistral': 605, 'n_tokens_neox': 573, 'n_words': 149}