Skip to content

Commit

Permalink
tinker
Browse files Browse the repository at this point in the history
  • Loading branch information
luoxiu committed Jul 29, 2018
1 parent 9fa0031 commit 6a6d49e
Show file tree
Hide file tree
Showing 22 changed files with 394 additions and 351 deletions.
11 changes: 1 addition & 10 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
ignore:
- "Tests/"

coverage:
precision: 2
range: 50...75
precision: 3

status:
project: yes
patch: yes
changes: no
- "Schedule.playground"
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2
4.0
11 changes: 3 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,10 @@ import PackageDescription
let package = Package(
name: "Schedule",
products: [
.library(
name: "Schedule",
targets: ["Schedule"])
.library(name: "Schedule", targets: ["Schedule"])
],
targets: [
.target(
name: "Schedule"),
.testTarget(
name: "ScheduleTests",
dependencies: ["Schedule"])
.target(name: "Schedule"),
.testTarget(name: "ScheduleTests", dependencies: ["Schedule"])
]
)
78 changes: 36 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,43 @@
![platform](https://img.shields.io/badge/platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS-333333.svg)
![cocoapods](https://img.shields.io/cocoapods/v/Schedule.svg)
![carthage](https://img.shields.io/badge/Carthage-compatible-brightgreen.svg)
![swift-package-manager](https://img.shields.io/badge/swift--package--manager-compatible-brightgreen.svg)

⏰ An interval-based and date-based task scheduler for swift, with incredibly smooth api.
![swift-package-manager](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)

⏳ An interval-based and date-based task scheduler for swift, with incredibly sweet api.

## Features

- 📆 Date-based scheduling
- Interval-based scheduling
- Interval-based scheduling
- 🌈 Mixture rules
- 📝 Human readable period parsing
- 📝 Human readable datetime parsing
- 🚦 Suspend, resume, cancel
- 🏷 Tag-based management
- 🍰 Action appending/removing
- 🚔 Thread safe
- 🍻 No need to concern about runloop
- 👻 No need to concern about circular reference
- 🍭 **Incredibly Smooth API**
- 🍭 **Incredibly Sweet API**


## Usage

Scheduling a task can not be simplier.

```swift
Schedule.every(1.second).do {
print("heart beat")
Schedule.after(3.seconds).do {
print("elapsed!")
}
```


### Interval-based Scheduling

```swift
import Schedule

Schedule.after(3.seconds).do {
print("hello")
}

Schedule.every(1.day).do { }
Schedule.every(1.seconds).do { }

Schedule.after(1.hour, repeating: 1.minute).do { }

Schedule.of(1.second, 2.minutes, 3.hours).do { }

Schedule.from([1.second, 2.minutes, 3.hours]).do { }
```


Expand All @@ -60,17 +50,15 @@ Schedule.from([1.second, 2.minutes, 3.hours]).do { }
```swift
import Schedule

Schedule.at(date).do { }
Schedule.at(when).do { }

Schedule.every(.monday, .tuesday).at("11:11").do { }
Schedule.every(.monday, .tuesday).at("9:00:00").do { }

Schedule.every(.september(30)).at("10:00:00").do { }
Schedule.every(.september(30)).at(10, 30).do { }

Schedule.every("one month and ten days").do { }

Schedule.of(date0, date1, date2).do { }

Schedule.from([date0, date1, date2]).do { }
```


Expand All @@ -95,27 +83,41 @@ holidaySchedule.do {
print("Happy holiday")
}

/// cut
/// first
let s5 = Schedule.after(5.seconds).concat(Schedule.every(1.day))
let s6 = s5.cut(10)
let s6 = s5.first(10)

/// until
let s7 = Schedule.every(.monday).at(11, 12)
let s8 = s7.until(date)
```

### Human readable datetime parsing

```swift
Schedule.every("one hour and ten minutes").do { }
```

### Task management

In general, you don't need to concern about the reference management of task. All tasks will be retained internally, so they won't be released, unless you do it yourself.

There is a more elegant way to deal with task's lifecycle:

```swift
Schedule.every(1.second).do(host: self) {
// do something, and cancel the task when `self` is deallocated.
}
```

#### Manipulation

```swift
let task = Schedule.every(1.day).do { }

task.suspend()
task.resume()
task.cancel() // will release this task after you cancel it.
task.cancel() // will decrease this task's ref count.
```

#### Tag
Expand All @@ -137,7 +139,7 @@ Task.cancel(byTag: "log")

#### Action

Aciton is minimal job unit. A task is composed of a series of actions.
`Aciton` is minimal job unit. A task is composed of a series of actions.

```swift
let dailyTask = Schedule.every(1.day)
Expand All @@ -153,7 +155,7 @@ let key = dailyTask.addAction {
dailyTask.removeAction(byKey: key)
```

### Lifecycle
#### Lifecycle

You can get the current timeline of the task:

Expand All @@ -172,20 +174,6 @@ task.addLifetime(1.hours)
task.restOfLifetime == 11.hours
```

### Parasitism

There is a more elegant way to deal with task's lifecycle:

```swift
Schedule.every(1.second).do(dependOn: self) {
// do something, and cancel the task when `self` is deallocated.
}
```

## Contribution

Feel free to criticize. 🍺

## Installation

Schedule supports all popular dependency managers.
Expand All @@ -209,3 +197,9 @@ dependencies: [
.package(url: "https://github.com/jianstm/Schedule", .upToNextMinor("0.0.0"))
]
```

## Contributing

Feel free to criticize! Any suggestion is welcome!

> Like **Schedule**? Star me and tell your friends!
16 changes: 16 additions & 0 deletions Schedule.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//: Playground - noun: a place where people can play

import PlaygroundSupport
import Foundation
import Schedule

PlaygroundPage.current.needsIndefiniteExecution = true

Schedule.after(1.second).do {
print("1 seconds passed!")
}

Schedule.every(.june(14)).at("9:30").do {
print("Happy birthday!")
}

4 changes: 4 additions & 0 deletions Schedule.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='macos'>
<timeline fileName='timeline.xctimeline'/>
</playground>
4 changes: 2 additions & 2 deletions Schedule.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "Schedule"
s.version = "0.0.5"
s.version = "0.0.6"
s.summary = "Task Scheduler for Swift."
s.homepage = "https://github.com/jianstm/Schedule"
s.license = { :type => "MIT", :file => "LICENSE" }
Expand All @@ -9,7 +9,7 @@ Pod::Spec.new do |s|
:tag => "#{s.version}" }
s.source_files = "Sources/Schedule/*.swift"
s.requires_arc = true
s.swift_version = "4.2"
s.swift_version = "4.0"

s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.10"
Expand Down

0 comments on commit 6a6d49e

Please sign in to comment.