<commit_before>//
//  deferred-extras.swift
//  async-deferred
//
//  Created by <NAME> on 2015-07-13.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Dispatch

/*
  Definitions that rely on or extend Deferred, but do not need the fundamental, private stuff.
*/

// MARK: minimum delay until a `Deferred` has a value

extension Deferred
{
  /// Return a `Deferred` whose determination will occur at least a number of seconds from the time of evaluation.
  /// Note that a cancelation or error will result in early determination.
  ///
  /// - parameter seconds: a number of seconds as a `Double` or `NSTimeInterval`
  /// - returns: a `Deferred` reference

  public final func delay(seconds s: Double) -> Deferred
  {
    if s > 0
    {
      return self.delay(until: .now() + s)
    }
    return self
  }

  /// Return a `Deferred` whose determination will occur at the earliest`delay` from the time of evaluation.
  /// Note that a cancelation or error will result in early determination.
  ///
  /// - parameter delay: a time interval, as `DispatchTimeInterval`
  /// - returns: a `Deferred` reference

  public final func delay(_ delay: DispatchTimeInterval) -> Deferred
  {
#if swift(>=3.2)
    if delay == .never
    {
      return self.delay(until: .distantFuture)
    }
#endif

    return self.delay(seconds: delay.seconds)
  }

  /// Return a `Deferred` whose determination will occur after a given timestamp.
  /// Note that a cancelation or error will result in early determination.
  ///
  /// - parameter seconds: a number of seconds as a `Double` or `NSTimeInterval`
  /// - returns: a `Deferred` reference

  public final func delay(until time: DispatchTime) -> Deferred
  {
    return Delayed(source: self, until: time)
  }
}

// MARK: maximum time until a `Deferred` becomes determined

@_versioned let DefaultTimeoutMessage = "Operation timed out"

extension Deferred
{
  /// Ensure this `Deferred` will be determined by the given deadline.
  /// If `self` has not become determined before the timeout expires, `self` will be canceled.
  ///
  /// - parameter seconds: a number of seconds as a `Double` or `NSTimeInterval`<commit_msg>simplify `delay` methods<commit_after>//
//  deferred-extras.swift
//  async-deferred
//
//  Created by <NAME> on 2015-07-13.
//  Copyright © 2015 <NAME>. All rights reserved.
//

import Dispatch

/*
  Definitions that rely on or extend Deferred, but do not need the fundamental, private stuff.
*/

// MARK: minimum delay until a `Deferred` has a value

extension Deferred
{
  /// Return a `Deferred` whose determination will occur at least a number of seconds from the time of evaluation.
  /// Note that a cancelation or error will result in early determination.
  ///
  /// - parameter seconds: a number of seconds as a `Double` or `NSTimeInterval`
  /// - returns: a `Deferred` reference

  public final func delay(seconds delay: Double) -> Deferred
  {
    return self.delay(until: .now() + delay)
  }

  /// Return a `Deferred` whose determination will occur at the earliest`delay` from the time of evaluation.
  /// Note that a cancelation or error will result in early determination.
  ///
  /// - parameter delay: a time interval, as `DispatchTimeInterval`
  /// - returns: a `Deferred` reference

  public final func delay(_ delay: DispatchTimeInterval) -> Deferred
  {
    return self.delay(until: .now() + delay)
  }

  /// Return a `Deferred` whose determination will occur after a given timestamp.
  /// Note that a cancelation or error will result in early determination.
  ///
  /// - parameter seconds: a number of seconds as a `Double` or `NSTimeInterval`
  /// - returns: a `Deferred` reference

  public final func delay(until time: DispatchTime) -> Deferred
  {
    guard time > .now() else { return self }

    return Delayed(source: self, until: time)
  }
}

// MARK: maximum time until a `Deferred` becomes determined

@_versioned let DefaultTimeoutMessage = "Operation timed out"

extension Deferred
{
  /// Ensure this `Deferred` will be determined by the given deadline.
  /// If `self` has not become determined before the timeout expires, `self` will be canceled.
  ///
  /// - parameter seconds: a number of seconds as a `Double` or `NSTimeInterval`
{'fraction_non_alphanumeric': 0.10532516493873705, 'fraction_numerical': 0.006361922714420358, 'mean_word_length': 3.0160832544938505, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 16, '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': '5883815', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1180, 'n_words': 512}