# 排程器 API

本頁列出 `core` 套件中建立、啟動與停止排程器的 API。

```go
import "github.com/pardnchiu/go-scheduler/core"
```

`New` 回傳未匯出的 `*cron`，其匯出方法可直接呼叫；需要儲存時以 `:=` 推導型別。

## Config

```go
type Config struct {
	Location *time.Location
}
```

| 欄位 | 說明 |
|---|---|
| `Location` | 排程時區；`nil` 時為 `time.Local` |

## New

```go
func New(c Config) (*cron, error)
```

建立排程器並初始化最小堆、解析器、依賴子系統與 logger。目前實作的 error 恆為 `nil`。

## Start

```go
func (c *cron) Start()
```

啟動依賴 Worker 池與事件迴圈，並為已註冊任務計算下次觸發時間。已啟動時為 no-op。

## Stop

```go
func (c *cron) Stop() context.Context
```

停止事件迴圈並等待依賴 Worker 結束，回傳在進行中無依賴任務結束後 cancel 的 context。

```go
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

select {
case <-c.Stop().Done():
case <-ctx.Done():
	log.Println("shutdown timeout")
}
```

註冊任務見 [任務 API](/zh/api-reference-tasks)，前置任務型別見 [依賴 API](/zh/api-reference-dependencies)。
