-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_source.go
31 lines (26 loc) · 964 Bytes
/
image_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package gostream
import (
"context"
"image"
)
// An ImageSource is responsible for producing images when requested. A source
// should produce the image as quickly as possible and introduce no rate limiting
// of its own as that is handled internally.
type ImageSource interface {
// Next returns an image along with a function to release
// the image once it is no longer used. Not calling the function
// will not leak memory but may cause the implementer to be
// as efficient with memory.
Next(ctx context.Context) (image.Image, func(), error)
Close() error
}
// An ImageSourceFunc is a helper to turn a function into an ImageSource
type ImageSourceFunc func(ctx context.Context) (image.Image, func(), error)
// Next calls the underlying function to get an image.
func (isf ImageSourceFunc) Next(ctx context.Context) (image.Image, func(), error) {
return isf(ctx)
}
// Close does nothing.
func (isf ImageSourceFunc) Close() error {
return nil
}