MCPcopy Index your code
hub / github.com/alex023/clock

github.com/alex023/clock @0.7.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.7.4 ↗ · + Follow
79 symbols 302 edges 7 files 44 documented · 56% 12 cross-repo links updated 6y ago★ 171
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Clock

License Go Report Card GoDoc Build Status Coverage Status

Brief

Timing task manager based on red black tree in memory

Feature

  • support task function call, and event notifications
  • support task that executes once or several times
  • support task cancel which added
  • fault isolation
  • 100k/s operation

last indicator may not be available on the cloud server,see more test code

# Example ## add a task that executes once ```golang var ( myClock = NewClock() jobFunc = func() { fmt.Println("schedule once") } ) //add a task that executes once,interval 100 millisecond myClock.AddJobWithInterval(time.Duration(100*time.Millisecond), jobFunc)

//wait a second,watching 
time.Sleep(1 * time.Second)

//Output:
//
//schedule once

## add repeat task that executes three timesgolang func ExampleClock_AddJobRepeat() { var ( myClock = NewClock() ) //define a repeat task fn := func() { fmt.Println("schedule repeat") } //add in clock,execute three times,interval 200 millisecond _, inserted := myClock.AddJobRepeat(time.Duration(time.Millisecond200), 3, fn) if !inserted { log.Println("failure") } //wait a second,watching time.Sleep(time.Second) //Output: // //schedule repeat //schedule repeat //schedule repeat } ## rm a task before its executiongolang func ExampleClock_RmJob(){ var ( myClock = NewClock() count int jobFunc = func() { count++ fmt.Println("do ",count) } ) //创建任务,间隔1秒,执行两次 job, _ := myClock.AddJobRepeat(time.Second1,2, jobFunc)

//任务执行前,撤销任务
time.Sleep(time.Millisecond*500)
job.Cancel()

//等待3秒,正常情况下,事件不会再执行
time.Sleep(3 * time.Second)

//Output:
//
//

} ``` ## more examples ### event notify ### TTL Session

Extension points exported contracts — how you extend this code

Job (Interface)
Job External access interface for timed tasks [1 implementers]
job.go

Core symbols most depended-on inside this repo

Count
called by 14
job.go
AddJobWithInterval
called by 13
clock.go
Reset
called by 13
clock.go
Default
called by 11
clock.go
NewClock
called by 11
clock.go
AddJobRepeat
called by 11
clock.go
WaitJobs
called by 10
clock.go
Cancel
called by 9
job.go

Shape

Method 40
Function 32
Struct 6
Interface 1

Languages

Go100%

Modules by API surface

clock.go23 symbols
clock_test.go19 symbols
job.go16 symbols
example/session.go8 symbols
clock_example_test.go5 symbols
safetimer.go4 symbols
rbtree_test.go4 symbols

For agents

$ claude mcp add clock \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page