<commit_before>//
//  deferred-delay.swift
//  deferred
//
//  Created by <NAME>
//  Copyright © 2017-2020 <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 resolution will occur at least a number of seconds from the time of evaluation.
  ///
  /// Note that a cancellation or error will result in early resolution.
  ///
  /// - parameter seconds: a number of seconds as a `Double` or `NSTimeInterval`
  /// - returns: a `Deferred` reference

  public func delay(queue: DispatchQueue? = nil, seconds delay: Double) -> Deferred
  {
    return self.delay(queue: queue, until: .now() + delay)
  }

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

  public func delay(queue: DispatchQueue? = nil, _ delay: DispatchTimeInterval) -> Deferred
  {
    return self.delay(queue: queue, until: .now() + delay)
  }

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

  public func delay(queue: DispatchQueue? = nil, until time: DispatchTime) -> Deferred
  {
    guard time > .now() else { return self }

    return Deferred(queue: queue ?? self.queue) {
      resolver in
      self.notify(queue: queue, boostQoS: false) {
        result in
        guard resolver.needsResolution else { return }

        if case .failure = result
        { // don't honor the time delay for the error case
          resolver.resolve(result)
          return
        }

        if time == .distantFuture { return }
        // enqueue block only if it can get executed
        if time > .now()<commit_msg>fix some doc-comments<commit_after>//
//  deferred-delay.swift
//  deferred
//
//  Created by <NAME>
//  Copyright © 2017-2020 <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 resolution will occur at least a number of seconds from the time of evaluation.
  ///
  /// Note that a cancellation or error will result in early resolution.
  ///
  /// - parameter queue: the `DispatchQueue` to attach to the new `Deferred`; defaults to `self`'s queue.
  /// - parameter delay: a number of seconds as a `Double` or `NSTimeInterval`
  /// - returns: a `Deferred` reference

  public func delay(queue: DispatchQueue? = nil, seconds delay: Double) -> Deferred
  {
    return self.delay(queue: queue, until: .now() + delay)
  }

  /// Return a `Deferred` whose resolution will occur at the earliest`delay` from the time of evaluation.
  ///
  /// Note that a cancellation or error will result in early resolution.
  ///
  /// - parameter queue: the `DispatchQueue` to attach to the new `Deferred`; defaults to `self`'s queue.
  /// - parameter delay: a time interval, as `DispatchTimeInterval`
  /// - returns: a `Deferred` reference

  public func delay(queue: DispatchQueue? = nil, _ delay: DispatchTimeInterval) -> Deferred
  {
    return self.delay(queue: queue, until: .now() + delay)
  }

  /// Return a `Deferred` whose resolution will occur after a given timestamp.
  ///
  /// Note that a cancellation or error will result in early resolution.
  ///
  /// - parameter queue: the `DispatchQueue` to attach to the new `Deferred`; defaults to `self`'s queue.
  /// - parameter time: a timestamp in the future
  /// - returns: a `Deferred` reference

  public func delay(queue: DispatchQueue? = nil, until time: DispatchTime) -> Deferred
  {
    guard time > .now() else { return self }

    return Deferred(queue: queue ?? self.queue) {
      resolver in
      self.notify(queue: queue, boostQoS: false) {
        result in
        guard resolver.needsResolution else { return }

        if case .failure = result
        { // don't honor the time delay for the error case
          resolver.resolve(result)
          return
        }

        if time == .distantFuture { return }
        // enqueue block only if it can get executed
        if time > .now()
{'fraction_non_alphanumeric': 0.10895361380798274, 'fraction_numerical': 0.003451995685005394, 'mean_word_length': 2.636078431372549, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3813811', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1280, 'n_words': 537}