github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/internal/poll/fd_poll.go (about) 1 // +build js 2 3 package poll 4 5 import "time" 6 7 // pollDesc is a no-op implementation of an I/O poller for GOARCH=js. 8 // 9 // Its implementation is based on NaCL in gc compiler (see GOROOT/src/internal/poll/fd_poll_nacl.go), 10 // but it does even less. 11 type pollDesc struct { 12 closing bool 13 } 14 15 func (pd *pollDesc) init(fd *FD) error { return nil } 16 17 func (pd *pollDesc) close() {} 18 19 func (pd *pollDesc) evict() { pd.closing = true } 20 21 func (pd *pollDesc) prepare(mode int, isFile bool) error { 22 if pd.closing { 23 return errClosing(isFile) 24 } 25 return nil 26 } 27 28 func (pd *pollDesc) prepareRead(isFile bool) error { return pd.prepare('r', isFile) } 29 30 func (pd *pollDesc) prepareWrite(isFile bool) error { return pd.prepare('w', isFile) } 31 32 func (pd *pollDesc) wait(mode int, isFile bool) error { 33 if pd.closing { 34 return errClosing(isFile) 35 } 36 return ErrTimeout 37 } 38 39 func (pd *pollDesc) waitRead(isFile bool) error { return pd.wait('r', isFile) } 40 41 func (pd *pollDesc) waitWrite(isFile bool) error { return pd.wait('w', isFile) } 42 43 func (*pollDesc) waitCanceled(mode int) {} 44 45 func (*pollDesc) pollable() bool { return true } 46 47 func (*FD) SetDeadline(t time.Time) error { return nil } 48 49 func (*FD) SetReadDeadline(t time.Time) error { return nil } 50 51 func (*FD) SetWriteDeadline(t time.Time) error { return nil } 52 53 // PollDescriptor returns the descriptor being used by the poller, 54 // or ^uintptr(0) if there isn't one. This is only used for testing. 55 func PollDescriptor() uintptr { 56 return ^uintptr(0) 57 } 58 59 // Copy of sync.runtime_Semacquire. 60 func runtime_Semacquire(s *uint32) { 61 if *s == 0 { 62 ch := make(chan bool) 63 semWaiters[s] = append(semWaiters[s], ch) 64 <-ch 65 } 66 *s-- 67 } 68 69 // Copy of sync.runtime_Semrelease. 70 func runtime_Semrelease(s *uint32) { 71 *s++ 72 73 w := semWaiters[s] 74 if len(w) == 0 { 75 return 76 } 77 78 ch := w[0] 79 w = w[1:] 80 semWaiters[s] = w 81 if len(w) == 0 { 82 delete(semWaiters, s) 83 } 84 85 ch <- true 86 } 87 88 var semWaiters = make(map[*uint32][]chan bool)