# Scheduler API

This page lists the `core` package API for creating, starting, and stopping a scheduler.

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

`New` returns the unexported `*cron`; its exported methods are callable directly, and `:=` infers the type when storing it.

## Config

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

| Field | Description |
|---|---|
| `Location` | Schedule timezone; `time.Local` when `nil` |

## New

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

Creates a scheduler and initializes the min-heap, parser, dependency subsystem, and logger. The current implementation always returns a `nil` error.

## Start

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

Starts the dependency worker pool and event loop and computes next fire times for registered tasks. No-op when already running.

## Stop

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

Stops the event loop, waits for dependency workers to exit, and returns a context cancelled after in-flight tasks without dependencies finish.

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

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

See [Task API](/api-reference-tasks) for registering tasks and [Dependency API](/api-reference-dependencies) for prerequisite types.
