Documentation ¶
Overview ¶
scheduler package provides a simple scheduler for concurrent execution of jobs.
Copyright 2020 KaaIoT Technologies, LLC ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrQueueFull = errors.New("queue full")
Functions ¶
This section is empty.
Types ¶
type Runnable ¶
type Runnable interface {
// Run a job
Run()
}
Runnable interface for scheduled jobs.
type Scheduler ¶
type Scheduler interface { // Schedule a job for execution, which may commence immediately, or at a later time, when a concurrent goroutine // becomes available. Jobs are started in FIFO fashion. // When the job queue is full, function returns ErrQueueFull. Schedule(job Runnable) error // Stop scheduler and accept no more Schedule() requests. // Completes the outstanding jobs, shuts down worker goroutines, and exits. // Consequent calls to Stop() will have no effect. Stop() }
Scheduler manages a dynamic pool of concurrent goroutines and dispatches Runnable jobs to them.
func NewScheduler ¶
NewScheduler creates and returns a new Scheduler. - maxConcurrency limits the maximum allowed number of goroutines. Value 0 indicates no limit (in which case all incoming jobs will be run concurrently immediately). - maxQueueSize limits the maximum allowed number of jobs waiting execution. One of the return values is always nil.