rgbkrk / libvirt-go

[DEPRECATED] Go bindings for libvirt
https://github.com/libvirt/libvirt-go
MIT License
166 stars 50 forks source link

[WIP] Ability to register timeout and handle events with the default loop #94

Closed vincentbernat closed 8 years ago

vincentbernat commented 8 years ago

The following functions are added:

The first commit is a preparation to have callbacks handled in a more generic way.

After writing this, I am a bit indecisive. The main goal of this PR is to be able to interrupt the event loop (notably useful for unittests). However, there is another way of doing the same thing: implementing the appropriate functions to integrate libvirt with Go scheduler. This way, no need to run a loop, and therefore, no need to interrupt it. If we go this way, the implementation of the above functions is useless (people would use goroutines instead).

Comments are welcome.

vincentbernat commented 8 years ago

I don't think this is the right way. I close the PR for now, I'll reopen it if I change my mind.

vincentbernat commented 8 years ago

After a night, I think no additional function is needed. I am just using this in my code:

func init() {
    go func() {
        if res := libvirt.EventRegisterDefaultImpl(); res != 0 {
            panic("unable to initialize libvirt event loop")
        }
        for {
            _ := libvirt.EventRunDefaultImpl()
        }
    }()
}

That's good enough. Being able to start/stop the loop is not really needed as it can be initialized only globally and only once, so even if we were able to start/stop it, it would carry state from other parts of the code.