Skip to content

heimdalr/updating-resource

Repository files navigation

updating-resource

Tests Go Reference Go Playground Go Report Card

updating-resource provides means to wrap objects whose value is then regularly and asynchronously computed / updated.

Example

package main

import (
	"fmt"
	"time"

	"github.com/heimdalr/updating-resource"
)

func main() {

	// the function to call
	var update = func(x interface{}) (interface{}, error) {
		y := x
		if y == nil { y = "" }
		return fmt.Sprintf("%s-", y), nil
	}

	// the resource config
	config := updatingresource.Config{
		Name:     "dashes",
		Update:   update,
		Interval: 20 * time.Millisecond,
	}
	resource := config.NewResource()

	fmt.Printf("%s\n", resource.Get().(string))

	time.Sleep(30 * time.Millisecond)
	fmt.Printf("%s\n", resource.Get().(string))

	time.Sleep(20 * time.Millisecond)
	fmt.Printf("%s\n", resource.Get().(string))

}

About

No description or website provided.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages