Code Monkey home page Code Monkey logo

cyetimer's Introduction

CYETimer

基于GCD DispatchSource封装的一个轻量级定时器,无循环引用问题,无RunLoop切换不同模式Timer定时器不准确问题,支持指定线程执行任务,线程安全。

Usage

定时器重复执行任务

//after:2秒后执行定时任务
//repeatIntervale:每1秒执行一次
//queue:globalQueue
func repeatButtonClick() {
        
        var count = 6
        var timerId: String? = ""
        
        timerId = CYETimer.repeatTask(after: 2,repeatIntervale: 1,queue: .global()) {
            
            count = count - 1
            
            if count == 0{
                //定时器销毁
                CYETimer.cancelTask(timerId: timerId)
                
            }
        }
    }

定时器单次执行任务

//1秒后mainQueue执行定时任务,自动销毁定时器
//内部处理定时器销毁
CYETimer.task(after: 1,queue: .main, task: {
            
})

定时器销毁

CYETimer.cancelTask(timerId: timerId)

销毁所有定时器

CYETimer.cancelAllTask()

Installation

CocoaPods:

pod 'CYETimer'

cyetimer's People

Contributors

caolaidong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.