-
Notifications
You must be signed in to change notification settings - Fork 67
/
channel.go
62 lines (50 loc) · 1.01 KB
/
channel.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package core
import (
"unsafe"
)
type (
FutureResult struct {
value Object
err Error
}
Channel struct {
ch chan FutureResult
isClosed bool
hash uint32
}
)
func MakeFutureResult(value Object, err Error) FutureResult {
return FutureResult{value: value, err: err}
}
func (ch *Channel) ToString(escape bool) string {
return "#object[Channel]"
}
func (ch *Channel) Equals(other interface{}) bool {
return ch == other
}
func (ch *Channel) GetInfo() *ObjectInfo {
return nil
}
func (ch *Channel) GetType() *Type {
return TYPE.Channel
}
func (ch *Channel) Hash() uint32 {
return ch.hash
}
func (ch *Channel) WithInfo(info *ObjectInfo) Object {
return ch
}
func MakeChannel(ch chan FutureResult) *Channel {
res := &Channel{ch: ch, hash: 0}
res.hash = HashPtr(uintptr(unsafe.Pointer(res)))
return res
}
func ExtractChannel(args []Object, index int) *Channel {
return EnsureArgIsChannel(args, index)
}
func (ch *Channel) Close() {
if !ch.isClosed {
close(ch.ch)
ch.isClosed = true
}
}