123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package svc
- import (
- "errors"
- "golang.org/x/sys/windows"
- )
- type event struct {
- h windows.Handle
- }
- func newEvent() (*event, error) {
- h, err := windows.CreateEvent(nil, 0, 0, nil)
- if err != nil {
- return nil, err
- }
- return &event{h: h}, nil
- }
- func (e *event) Close() error {
- return windows.CloseHandle(e.h)
- }
- func (e *event) Set() error {
- return windows.SetEvent(e.h)
- }
- func (e *event) Wait() error {
- s, err := windows.WaitForSingleObject(e.h, windows.INFINITE)
- switch s {
- case windows.WAIT_OBJECT_0:
- break
- case windows.WAIT_FAILED:
- return err
- default:
- return errors.New("unexpected result from WaitForSingleObject")
- }
- return nil
- }
|