Implement `MainLoopSynchronizationContext.Send`
- [x] I agree that my contribution may be licensed either under MIT or any version of LGPL license.
Tests still need to be written, if they are necessary.
Thanks for your PR. We explicitly did not implement the Send method as we did not know how to invoke / test it (see: https://github.com/gircore/gir.core/pull/856#issuecomment-1526969582).
Do you have any insight on how to trigger the method or for which use cases it is used (perhaps even some examples / documentation)?
If this is clarified we can go ahead and add some tests to your PR and then merge it.
The tests should probably be part of: https://github.com/gircore/gir.core/blob/main/src/Tests/Libs/GLib-2.0.Tests/SynchronizationContextTest.cs
Thanks for the swift response.
Our use case involved creating our own ExecuteInMainContext function, which directly called SynchronizationContext.Post for a blocking implementation. (see: Launcher.cs)
We acquired a reference to the GLib MainLoopSynchronizationContext through SynchronizationContext.Current inside of our Gtk.Application.OnActivate event. (see: MainCommands.cs)
I'm not exactly sure how to integrate this into the GLib tests either.
After reading several implementations I think the correct thing to do would be to call MainLoop.Invoke as it does the right thing as far as I understand. Your implementation is basically the last resort execution mentioned in the linked documentation which is fine but misses some optimizations mentioned there.
To test this I think it would be okay to manually invoke the Send method.
@cameronwhite: any thoughts?
My understanding is that g_main_context_invoke() would be more optimal if this happens to be called while already on the main UI thread since it'll call the function immediately, but otherwise it's equivalent to idle_add()