<commit_before>//
//  UISpider+Async.swift
//  Spider-Web
//
//  Created by <NAME> on 1/26/22.
//

import Foundation

@available(iOS 13, *)
@available(macOS 12, *)
public extension UISpider where T: ImageView {
    
    /// Fetches a remote _or_ cached image for a given URL, then assigns it to the current image view.
    /// - parameter url: The image's URL.
    /// - parameter placeholder: A placeholder image to assign to the current image view while the image is being fetched; _defaults to nil_.
    /// - parameter cacheImage: Flag indicating if the fetched image should be cached; _defaults to true_.
    /// - returns: A nullable image result.
    ///
    /// The caller is responsible for assigning the image to the image view.
    func setImage(_ url: URLRepresentable,
                  placeholder: Image? = nil,
                  cacheImage: Bool = true) async -> (Image?, Bool) {
        
        await withCheckedContinuation { c in
            setImage(url, placeholder: placeholder, cacheImage: cacheImage) { image, fromCache, error in
                c.resume(returning: (image, fromCache))
            }
        }
        
    }
    
    /// Fetches a remote _or_ cached image for a given URL, then assigns it to the current image view.
    /// - parameter url: The image's URL.
    /// - parameter placeholder: A placeholder image to assign to the current image view while the image is being fetched; _defaults to nil_.
    /// - parameter cacheImage: Flag indicating if the fetched image should be cached; _defaults to true_.
    /// - returns: An image result.
    ///
    /// The caller is responsible for assigning the image to the image view.
    func setImage(_ url: URLRepresentable,
                  placeholder: Image? = nil,
                  cacheImage: Bool = true) async throws -> (Image, Bool) {
        
        try await withCheckedThrowingContinuation { c in
            
            setImage(url, placeholder: placeholder, cacheImage: cacheImage) { image, fromCache, error in
                
                if let error = error {
                    c.resume(throwing: error)
                    return
                }
                else if let image = image {
                    c.resume(returning: (image, fromCache))
                    return
                }
                
                c.resume(throwing: ErrorType.invalidImage)<commit_msg>Updated function name<commit_after>//
//  UISpider+Async.swift
//  Spider-Web
//
//  Created by <NAME> on 1/26/22.
//

import Foundation

@available(iOS 13, *)
@available(macOS 12, *)
public extension UISpider where T: ImageView {
    
    /// Fetches a remote _or_ cached image for a given URL, then assigns it to the current image view.
    /// - parameter url: The image's URL.
    /// - parameter placeholder: A placeholder image to assign to the current image view while the image is being fetched; _defaults to nil_.
    /// - parameter cacheImage: Flag indicating if the fetched image should be cached; _defaults to true_.
    /// - returns: An optional image result.
    ///
    /// The caller is responsible for assigning the image to the image view.
    func setImage(_ url: URLRepresentable,
                  placeholder: Image? = nil,
                  cacheImage: Bool = true) async -> (Image?, Bool) {
        
        await withCheckedContinuation { c in
            setImage(url, placeholder: placeholder, cacheImage: cacheImage) { image, fromCache, error in
                c.resume(returning: (image, fromCache))
            }
        }
        
    }
    
    /// Fetches a remote _or_ cached image for a given URL, then assigns it to the current image view.
    /// - parameter url: The image's URL.
    /// - parameter placeholder: A placeholder image to assign to the current image view while the image is being fetched; _defaults to nil_.
    /// - parameter cacheImage: Flag indicating if the fetched image should be cached; _defaults to true_.
    /// - returns: An image result.
    ///
    /// The caller is responsible for assigning the image to the image view.
    func setImageThrowing(_ url: URLRepresentable,
                          placeholder: Image? = nil,
                          cacheImage: Bool = true) async throws -> (Image, Bool) {
        
        try await withCheckedThrowingContinuation { c in
            
            setImage(url, placeholder: placeholder, cacheImage: cacheImage) { image, fromCache, error in
                
                if let error = error {
                    c.resume(throwing: error)
                    return
                }
                else if let image = image {
                    c.resume(returning: (image, fromCache))
                    return
                }
                
                c.resume(throwing: ErrorType.invalidImage)
{'fraction_non_alphanumeric': 0.08193668528864059, 'fraction_numerical': 0.0037243947858473, 'mean_word_length': 1.828554710356934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '3857272', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1188, 'n_words': 489}