//
//  MPPositive_Debouncer.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/5/21.
//

import UIKit

class MPPositive_Debouncer: NSObject {
    static let shared = MPPositive_Debouncer()
    //计时器
    private var timer: Timer?
    private override init() {
        super.init()
    }
    deinit {
        timer?.invalidate()
        timer = nil
    }
    func call(_ delay:TimeInterval = 0.15, action:@escaping (() -> Void)) {
        // 取消之前的延迟调用
        timer?.invalidate()
        timer = nil
        // 设置新的延迟调用
        timer = Timer.scheduledTimer(withTimeInterval: delay, repeats: false) { _ in
            action()
        }
    }
}
