<commit_before>﻿namespace Pomodoro
{
    using System;
    using System.Timers;
    using Timer;

    public class SystemTimeMaster : TimeMaster
    {
        private readonly System.Timers.Timer _secondTimer;
        private TimeSpan _timeLeft;
        private System.Timers.Timer _currentTimer;
        private Action _callback;

        public SystemTimeMaster()
        {
            _secondTimer = new System.Timers.Timer(1000) {AutoReset = true};
            _secondTimer.Elapsed += OnSecondElapsed;
        }

        private void OnSecondElapsed(object sender, ElapsedEventArgs e)
        {
            if (_timeLeft == TimeSpan.Zero)
            {
                return;
            }

            _timeLeft -= TimeSpan.FromSeconds(1);

            if (Tick != null)
            {
                Tick(this, new TimeRemainingEventArgs
                {
                    TimeRemaining = _timeLeft
                });
            }
        }

        public void Pass(TimeSpan timeInterval, Action callback)
        {
            _timeLeft = timeInterval;
            _currentTimer = new System.Timers.Timer(timeInterval.TotalMilliseconds)
            {
                AutoReset = false
            };
            _currentTimer.Elapsed += OnIntervalTimerElapsed;
            _callback = callback;

            _secondTimer.Start();
            _currentTimer.Start();
        }

        private void OnIntervalTimerElapsed(object sender, ElapsedEventArgs e)
        {
            _secondTimer.Stop();
            _callback.Invoke();
        }

        public event EventHandler<TimeRemainingEventArgs> Tick;
        public void Stop()
        {
            _secondTimer.Stop();
            _currentTimer.Stop();
        }
    }
}<commit_msg>fixed a bug where restarting pomodoro would later cause multiple events to be fired - I simply hate time<commit_after>﻿namespace Pomodoro
{
    using System;
    using System.Timers;
    using Timer;

    public class SystemTimeMaster : TimeMaster
    {
        private readonly System.Timers.Timer _secondTimer;
        private TimeSpan _timeLeft;
        private readonly System.Timers.Timer _currentTimer;
        private Action _callback;

        public SystemTimeMaster()
        {
            _secondTimer = new System.Timers.Timer(1000) {AutoReset = true};
            _secondTimer.Elapsed += OnSecondElapsed;
            _currentTimer = new System.Timers.Timer
            {
                AutoReset = false
            };
            _currentTimer.Elapsed += OnIntervalTimerElapsed;
        }

        private void OnSecondElapsed(object sender, ElapsedEventArgs e)
        {
            if (_timeLeft == TimeSpan.Zero)
            {
                return;
            }

            _timeLeft -= TimeSpan.FromSeconds(1);

            if (Tick != null)
            {
                Tick(this, new TimeRemainingEventArgs
                {
                    TimeRemaining = _timeLeft
                });
            }
        }

        public void Pass(TimeSpan timeInterval, Action callback)
        {
            _timeLeft = timeInterval;
            _currentTimer.Stop();
            _currentTimer.Interval = timeInterval.TotalMilliseconds;
            _callback = callback;

            _secondTimer.Start();
            _currentTimer.Start();
        }

        private void OnIntervalTimerElapsed(object sender, ElapsedEventArgs e)
        {
            _secondTimer.Stop();
            _callback.Invoke();
        }

        public event EventHandler<TimeRemainingEventArgs> Tick;
        public void Stop()
        {
            _secondTimer.Stop();
            _currentTimer.Stop();
        }
    }
}
{'fraction_non_alphanumeric': 0.07183673469387755, 'fraction_numerical': 0.0027210884353741495, 'mean_word_length': 1.5688329839273236, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2984592', 'n_tokens_mistral': 926, 'n_tokens_neox': 884, 'n_words': 201}