<commit_before>//
//  TaskRetryHelper.swift
//  Pods
//
//  Created by <NAME> on 29/1/17.
//
//

import UIKit

public class TaskRetryHelper {
    
    public let waitTimeline: [TimeInterval]
    public var maxNumRetries: Int {
        return waitTimeline.count
    }
    public private(set) var availableNumRetries: Int
    
    public init(waitTimeline: [TimeInterval]) {
        self.waitTimeline = waitTimeline
        self.availableNumRetries = waitTimeline.count
    }
    
    // Perform a time delayed retry if one is still available, otherwise perform some give-up code
    public func retryOrNah(queue: DispatchQueue = DispatchQueue.main, retry: @escaping ()->(), nah: @escaping ()->()) {
        
        if availableNumRetries > 0 {
            let wait = waitTimeline[maxNumRetries - availableNumRetries]
            availableNumRetries = availableNumRetries - 1
            queue.asyncAfter(deadline: .now() + wait) {
                retry()
            }
        } else {
            queue.async {
                nah()
            }
        }
    }
    
    public class func exponentialBackoffTimeline(forMaxRetries maxRetries: Int, startingAt initialWait: TimeInterval) -> [TimeInterval] {
        var toReturn = Array<TimeInterval>()
        toReturn.append(initialWait)
        for ii in 1..<maxRetries {
            let next = toReturn[ii - 1] * 2.0
            toReturn.append(next)
        }
        return toReturn
    }
}
<commit_msg>Fixed glitch in the little exponential back off timeline algorithm<commit_after>//
//  TaskRetryHelper.swift
//  Pods
//
//  Created by <NAME> on 29/1/17.
//
//

import UIKit

public class TaskRetryHelper {
    
    public let waitTimeline: [TimeInterval]
    public var maxNumRetries: Int {
        return waitTimeline.count
    }
    public private(set) var availableNumRetries: Int
    
    public init(waitTimeline: [TimeInterval]) {
        self.waitTimeline = waitTimeline
        self.availableNumRetries = waitTimeline.count
    }
    
    // Perform a time delayed retry if one is still available, otherwise perform some give-up code
    public func retryOrNah(queue: DispatchQueue = DispatchQueue.main, retry: @escaping ()->(), nah: @escaping ()->()) {
        
        if availableNumRetries > 0 {
            let wait = waitTimeline[maxNumRetries - availableNumRetries]
            availableNumRetries = availableNumRetries - 1
            queue.asyncAfter(deadline: .now() + wait) {
                retry()
            }
        } else {
            queue.async {
                nah()
            }
        }
    }
    
    public class func exponentialBackoffTimeline(forMaxRetries maxRetries: Int, startingAt initialWait: TimeInterval) -> [TimeInterval] {
        var toReturn = Array<TimeInterval>()
        toReturn.append(max(initialWait, 0.0))
        for ii in 1..<maxRetries {
            var next = toReturn[ii - 1] * 2.0
            if next == 0.0 {
                next = 1.0
            }
            toReturn.append(next)
        }
        return toReturn
    }
}

{'fraction_non_alphanumeric': 0.09347326992456544, 'fraction_numerical': 0.009183338799606429, 'mean_word_length': 1.9872673849167484, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, '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': '4133333', 'n_tokens_mistral': 896, 'n_tokens_neox': 869, 'n_words': 219}