Compare commits
	
		
			2 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | d5519cc064 | ||
|   | f2a0830ca1 | 
							
								
								
									
										39
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								README.md
									
									
									
									
									
								
							| @ -7,28 +7,39 @@ cycle-scheduler is a simple scheduler lib, handling tasks and executes them at r | |||||||
| ## Examples | ## Examples | ||||||
| * Init a new scheduler with 4 workers | * Init a new scheduler with 4 workers | ||||||
| ```go | ```go | ||||||
|  | package main | ||||||
|  | 
 | ||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"time" | ||||||
| 
 | 
 | ||||||
| 	scheduler "gitea.thegux.fr/rmanach/cycle-scheduler.git" | 	scheduler "gitea.thegux.fr/rmanach/cycle-scheduler.git" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| ctx := context.Background() | func main() { | ||||||
| s := scheduler.NewSchedulerCycle(ctx, 4) | 	ctx, fnCancel := context.WithCancel(context.Background()) | ||||||
|  | 	s := scheduler.NewSchedulerCycle(ctx, 4) | ||||||
| 
 | 
 | ||||||
| // add a task with an execution interval of 2 ms (executed every 2 ms) | 	// add a task with an execution interval of 2 ms (executed every 2 ms) | ||||||
| // and a maximum duration of 30 second. | 	// and a maximum duration of 30 second. | ||||||
| taskID := s.Delay( | 	s.Delay( | ||||||
| 	func(ctx context.Context) (any, error) { | 		func(ctx context.Context) (any, error) { | ||||||
| 		// ... | 			// ... | ||||||
| 		return any, nil | 			return nil, nil | ||||||
| 	},  | 		}, | ||||||
| 	scheduler.WithExecInterval(2*time.Millisecond), | 		scheduler.WithExecInterval(2*time.Millisecond), | ||||||
| 	scheduler.WithMaxDuration(30*time.Second) | 		scheduler.WithMaxDuration(30*time.Second), | ||||||
| ) | 	) | ||||||
| 
 | 
 | ||||||
| <-ctx.Done() | 	// stop the program after 5 seconds | ||||||
| <-s.Done() | 	go func() { | ||||||
|  | 		time.Sleep(5 * time.Second) | ||||||
|  | 		fnCancel() | ||||||
|  | 	}() | ||||||
|  | 
 | ||||||
|  | 	<-ctx.Done() | ||||||
|  | 	<-s.Done() | ||||||
|  | } | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| **NOTE**: for `Delay` optionals arguments, check the `NewTask` method documentation for more details. | **NOTE**: for `Delay` optionals arguments, check the `NewTask` method documentation for more details. | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user