https://github.com/perfectlysoft/perfect-repeater
A simple library that takes a closure and executes it at the specified interval until the closure returns false or the application is terminated.
https://github.com/perfectlysoft/perfect-repeater
server-side-swift swift
Last synced: about 1 year ago
JSON representation
A simple library that takes a closure and executes it at the specified interval until the closure returns false or the application is terminated.
- Host: GitHub
- URL: https://github.com/perfectlysoft/perfect-repeater
- Owner: PerfectlySoft
- License: apache-2.0
- Created: 2017-03-07T18:37:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-22T17:11:55.000Z (about 7 years ago)
- Last Synced: 2025-05-22T17:19:20.934Z (about 1 year ago)
- Topics: server-side-swift, swift
- Language: Swift
- Homepage:
- Size: 8.79 KB
- Stars: 5
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Perfect Repeater
The Perfect "Repeater" is a simple library that takes a closure and executes it at the specified interval until the closure returns false or the application is terminated.
Note that a demo is located at [https://github.com/PerfectExamples/Perfect-Repeater-Demo](https://github.com/PerfectExamples/Perfect-Repeater-Demo) that shows the operation of the library.
## Compatibility with Swift
The master branch of this project currently compiles with **Xcode 9** or the **Swift 4** toolchain on Ubuntu, and is compatible with both Perfect 2.x and 3.x
## Building
Add this project as a dependency in your Package.swift file.
``` swift
.Package(url:"https://github.com/PerfectlySoft/Perfect-Repeater.git", majorVersion: 1)
```
## Usage
Include in your file the import statement:
``` swift
import PerfectRepeater
```
The base form of executing this is:
``` swift
Repeater.exec(timer: , callback: )
```
To demonstrate the process of repeating a closure containing your code and optionally re-queuing:
``` swift
var opt = 1
let c = {
() -> Bool in
print("XXXXXX")
return true
}
let cc = {
() -> Bool in
print("Hello, world! (\(opt))")
if opt < 10 {
opt += 1
return true
} else {
print("cc exiting.")
return false
}
}
Repeater.exec(timer: 3.0, callback: c)
Repeater.exec(timer: 2.0, callback: cc)
```
## Further Information
For more information on the Perfect project, please visit [perfect.org](http://perfect.org).