From d961df834c5709eb299cc6c02261eb7800c5618e Mon Sep 17 00:00:00 2001 From: Mike D Pilsbury Date: Sun, 30 Dec 2018 16:18:46 +0000 Subject: [PATCH] Add a note about glib.IdleAddOnce in documentation. --- docs-src/content/goroutines.md | 20 ++++++++++++++++++++ docs/goroutines/index.html | 19 ++++++++++++++++++- docs/index.json | 2 +- lib/glib/main_event_loop.go | 2 +- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/docs-src/content/goroutines.md b/docs-src/content/goroutines.md index 54b05bbd..576252bd 100644 --- a/docs-src/content/goroutines.md +++ b/docs-src/content/goroutines.md @@ -10,6 +10,8 @@ To perform such a call from a goroutine, use `glib.IdleAdd` to schedule invocation of a callback function on the main thread. +## `IdleAdd` + ```go glib.IdleAdd(func() bool { someLabel.SetText("some text") @@ -21,3 +23,21 @@ Return `glib.SOURCE_REMOVE` to ensure the function is not called again next time the main loop is idle. Alternatively return `glib.SOURCE_CONTINUE` to have the function called again. + +## `IdleAddOnce` + +Alternatively, `glib.IdleAddOnce` +schedules a _single_ invocation of a +callback function on the main thread. +Unlike `glib.IdleAdd` no value needs to be returned +to avoid subsequent invocations of the callback. + + +```go +glib.IdleAddOnce(func() { + someLabel.SetText("some text") +}) +``` + +`IdleAddOnce` is a convenience provided by gobbi. +It has no direct equivalent in the glib C library. diff --git a/docs/goroutines/index.html b/docs/goroutines/index.html index 2961e888..ae300077 100644 --- a/docs/goroutines/index.html +++ b/docs/goroutines/index.html @@ -176,11 +176,15 @@

Goroutines

-

All calls to gtk functions should be performed on + + +

All calls to gtk functions should be performed on the main thread. To perform such a call from a goroutine, use glib.IdleAdd to schedule invocation of a callback function on the main thread.

+ +

IdleAdd

glib.IdleAdd(func() bool {
     someLabel.SetText("some text")
     return glib.SOURCE_REMOVE
@@ -190,6 +194,19 @@ 

Goroutines

Alternatively return glib.SOURCE_CONTINUE to have the function called again.

+

IdleAddOnce

+ +

Alternatively, glib.IdleAddOnce +schedules a single invocation of a +callback function on the main thread. +Unlike glib.IdleAdd no value needs to be returned +to avoid subsequent invocations of the callback.

+
glib.IdleAddOnce(func() {
+    someLabel.SetText("some text")
+})
+

IdleAddOnce is a convenience provided by gobbi. +It has no direct equivalent in the glib C library.

+ diff --git a/docs/index.json b/docs/index.json index 68caa7e8..8e4ccb9a 100644 --- a/docs/index.json +++ b/docs/index.json @@ -32,7 +32,7 @@ "title": "Goroutines", "tags": [], "description": "", - "content": "All calls to gtk functions should be performed on the main thread. To perform such a call from a goroutine, use glib.IdleAdd to schedule invocation of a callback function on the main thread.\nglib.IdleAdd(func() bool { someLabel.SetText(\u0026#34;some text\u0026#34;) return glib.SOURCE_REMOVE }) Return glib.SOURCE_REMOVE to ensure the function is not called again next time the main loop is idle. Alternatively return glib.SOURCE_CONTINUE to have the function called again.\n" + "content": " All calls to gtk functions should be performed on the main thread. To perform such a call from a goroutine, use glib.IdleAdd to schedule invocation of a callback function on the main thread.\nIdleAdd glib.IdleAdd(func() bool { someLabel.SetText(\u0026#34;some text\u0026#34;) return glib.SOURCE_REMOVE }) Return glib.SOURCE_REMOVE to ensure the function is not called again next time the main loop is idle. Alternatively return glib.SOURCE_CONTINUE to have the function called again.\nIdleAddOnce Alternatively, glib.IdleAddOnce schedules a single invocation of a callback function on the main thread. Unlike glib.IdleAdd no value needs to be returned to avoid subsequent invocations of the callback.\nglib.IdleAddOnce(func() { someLabel.SetText(\u0026#34;some text\u0026#34;) }) IdleAddOnce is a convenience provided by gobbi. It has no direct equivalent in the glib C library.\n" }, { "uri": "https://pekim.github.io/gobbi/gvalue/", diff --git a/lib/glib/main_event_loop.go b/lib/glib/main_event_loop.go index 41b54bb3..5774e937 100644 --- a/lib/glib/main_event_loop.go +++ b/lib/glib/main_event_loop.go @@ -52,7 +52,7 @@ sources after one invocation. That is, the callback will only be called once. func IdleAddOnce(callback IdleAddOnceCallback) { IdleAdd(func() bool { callback() - return false + return SOURCE_REMOVE }) }