@gtkx/ffi 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/dist/cairo/cairo.js +1 -1
  2. package/dist/codegen/ffi-generator.js +37 -12
  3. package/dist/generated/adw/index.d.ts +0 -1
  4. package/dist/generated/adw/index.js +0 -1
  5. package/dist/generated/adw/preferences-group.d.ts +0 -11
  6. package/dist/generated/adw/preferences-group.js +0 -36
  7. package/dist/generated/atspi/device.d.ts +0 -15
  8. package/dist/generated/atspi/device.js +0 -65
  9. package/dist/generated/atspi/functions.d.ts +4 -14
  10. package/dist/generated/atspi/functions.js +0 -48
  11. package/dist/generated/atspi/index.d.ts +0 -2
  12. package/dist/generated/atspi/index.js +0 -2
  13. package/dist/generated/gdk/cursor.d.ts +1 -12
  14. package/dist/generated/gdk/cursor.js +22 -55
  15. package/dist/generated/gdk/functions.d.ts +0 -26
  16. package/dist/generated/gdk/functions.js +0 -74
  17. package/dist/generated/gdk/texture.d.ts +0 -10
  18. package/dist/generated/gdk/texture.js +0 -36
  19. package/dist/generated/gdkpixbuf/pixbuf.d.ts +0 -49
  20. package/dist/generated/gdkpixbuf/pixbuf.js +0 -166
  21. package/dist/generated/gio/app-info.d.ts +0 -15
  22. package/dist/generated/gio/app-info.js +0 -50
  23. package/dist/generated/gio/async-initable.d.ts +0 -44
  24. package/dist/generated/gio/async-initable.js +0 -69
  25. package/dist/generated/gio/buffered-input-stream.d.ts +0 -14
  26. package/dist/generated/gio/buffered-input-stream.js +0 -44
  27. package/dist/generated/gio/bytes-icon.d.ts +0 -10
  28. package/dist/generated/gio/bytes-icon.js +0 -36
  29. package/dist/generated/gio/cancellable.d.ts +0 -41
  30. package/dist/generated/gio/cancellable.js +0 -62
  31. package/dist/generated/gio/data-input-stream.d.ts +0 -59
  32. package/dist/generated/gio/data-input-stream.js +0 -149
  33. package/dist/generated/gio/dbus-connection.d.ts +1 -374
  34. package/dist/generated/gio/dbus-connection.js +0 -761
  35. package/dist/generated/gio/dbus-object-manager-client.d.ts +1 -120
  36. package/dist/generated/gio/dbus-object-manager-client.js +0 -354
  37. package/dist/generated/gio/dbus-proxy.d.ts +0 -163
  38. package/dist/generated/gio/dbus-proxy.js +0 -379
  39. package/dist/generated/gio/drive.d.ts +1 -62
  40. package/dist/generated/gio/drive.js +0 -200
  41. package/dist/generated/gio/dtls-connection.d.ts +0 -29
  42. package/dist/generated/gio/dtls-connection.js +0 -115
  43. package/dist/generated/gio/file-enumerator.d.ts +0 -85
  44. package/dist/generated/gio/file-enumerator.js +0 -141
  45. package/dist/generated/gio/file-icon.d.ts +0 -10
  46. package/dist/generated/gio/file-icon.js +0 -36
  47. package/dist/generated/gio/file-input-stream.d.ts +0 -19
  48. package/dist/generated/gio/file-input-stream.js +0 -49
  49. package/dist/generated/gio/file-iostream.d.ts +0 -14
  50. package/dist/generated/gio/file-iostream.js +0 -44
  51. package/dist/generated/gio/file-output-stream.d.ts +0 -14
  52. package/dist/generated/gio/file-output-stream.js +0 -44
  53. package/dist/generated/gio/file.d.ts +1 -661
  54. package/dist/generated/gio/file.js +58 -1899
  55. package/dist/generated/gio/functions.d.ts +0 -261
  56. package/dist/generated/gio/functions.js +0 -666
  57. package/dist/generated/gio/index.d.ts +0 -2
  58. package/dist/generated/gio/index.js +0 -2
  59. package/dist/generated/gio/input-stream.d.ts +0 -127
  60. package/dist/generated/gio/input-stream.js +0 -293
  61. package/dist/generated/gio/iostream.d.ts +0 -34
  62. package/dist/generated/gio/iostream.js +0 -93
  63. package/dist/generated/gio/list-store.d.ts +0 -46
  64. package/dist/generated/gio/list-store.js +0 -139
  65. package/dist/generated/gio/loadable-icon.d.ts +0 -10
  66. package/dist/generated/gio/loadable-icon.js +0 -36
  67. package/dist/generated/gio/mount.d.ts +0 -74
  68. package/dist/generated/gio/mount.js +0 -243
  69. package/dist/generated/gio/network-monitor.d.ts +0 -16
  70. package/dist/generated/gio/network-monitor.js +0 -42
  71. package/dist/generated/gio/output-stream.d.ts +0 -200
  72. package/dist/generated/gio/output-stream.js +0 -469
  73. package/dist/generated/gio/permission.d.ts +0 -20
  74. package/dist/generated/gio/permission.js +0 -64
  75. package/dist/generated/gio/proxy-resolver.d.ts +0 -9
  76. package/dist/generated/gio/proxy-resolver.js +0 -35
  77. package/dist/generated/gio/proxy.d.ts +0 -9
  78. package/dist/generated/gio/proxy.js +0 -39
  79. package/dist/generated/gio/resolver.d.ts +0 -59
  80. package/dist/generated/gio/resolver.js +0 -205
  81. package/dist/generated/gio/settings.d.ts +0 -33
  82. package/dist/generated/gio/settings.js +0 -53
  83. package/dist/generated/gio/simple-proxy-resolver.d.ts +0 -9
  84. package/dist/generated/gio/simple-proxy-resolver.js +0 -35
  85. package/dist/generated/gio/socket-address-enumerator.d.ts +0 -10
  86. package/dist/generated/gio/socket-address-enumerator.js +0 -32
  87. package/dist/generated/gio/socket-client.d.ts +0 -57
  88. package/dist/generated/gio/socket-client.js +0 -173
  89. package/dist/generated/gio/socket-connection.d.ts +0 -17
  90. package/dist/generated/gio/socket-connection.js +0 -43
  91. package/dist/generated/gio/socket-listener.d.ts +0 -22
  92. package/dist/generated/gio/socket-listener.js +0 -66
  93. package/dist/generated/gio/subprocess.d.ts +0 -36
  94. package/dist/generated/gio/subprocess.js +0 -139
  95. package/dist/generated/gio/tls-connection.d.ts +0 -9
  96. package/dist/generated/gio/tls-connection.js +0 -35
  97. package/dist/generated/gio/tls-database.d.ts +0 -51
  98. package/dist/generated/gio/tls-database.js +0 -205
  99. package/dist/generated/gio/tls-interaction.d.ts +0 -38
  100. package/dist/generated/gio/tls-interaction.js +0 -94
  101. package/dist/generated/gio/unix-connection.d.ts +0 -26
  102. package/dist/generated/gio/unix-connection.js +0 -70
  103. package/dist/generated/gio/vfs.d.ts +0 -30
  104. package/dist/generated/gio/vfs.js +0 -71
  105. package/dist/generated/gio/volume.d.ts +0 -32
  106. package/dist/generated/gio/volume.js +0 -117
  107. package/dist/generated/giounix/desktop-app-info.d.ts +0 -58
  108. package/dist/generated/giounix/desktop-app-info.js +0 -226
  109. package/dist/generated/glib/byte-array.d.ts +0 -23
  110. package/dist/generated/glib/byte-array.js +0 -62
  111. package/dist/generated/glib/error.d.ts +0 -36
  112. package/dist/generated/glib/error.js +0 -82
  113. package/dist/generated/glib/functions.d.ts +1 -811
  114. package/dist/generated/glib/functions.js +55 -1787
  115. package/dist/generated/glib/hash-table.d.ts +0 -64
  116. package/dist/generated/glib/hash-table.js +0 -148
  117. package/dist/generated/glib/main-context.d.ts +0 -17
  118. package/dist/generated/glib/main-context.js +0 -37
  119. package/dist/generated/glib/option-group.d.ts +0 -12
  120. package/dist/generated/glib/option-group.js +0 -39
  121. package/dist/generated/glib/regex.d.ts +0 -54
  122. package/dist/generated/glib/regex.js +0 -107
  123. package/dist/generated/glib/source.d.ts +0 -27
  124. package/dist/generated/glib/source.js +0 -43
  125. package/dist/generated/glib/thread.d.ts +2 -46
  126. package/dist/generated/glib/thread.js +5 -50
  127. package/dist/generated/glib/tree.d.ts +2 -74
  128. package/dist/generated/glib/tree.js +4 -192
  129. package/dist/generated/glibunix/functions.d.ts +0 -2
  130. package/dist/generated/glibunix/functions.js +0 -45
  131. package/dist/generated/gobject/binding-group.d.ts +0 -17
  132. package/dist/generated/gobject/binding-group.js +0 -59
  133. package/dist/generated/gobject/functions.d.ts +0 -40
  134. package/dist/generated/gobject/functions.js +0 -95
  135. package/dist/generated/gobject/object.d.ts +0 -33
  136. package/dist/generated/gobject/object.js +0 -77
  137. package/dist/generated/gobject/signal-group.d.ts +0 -23
  138. package/dist/generated/gobject/signal-group.js +0 -70
  139. package/dist/generated/gobject/value-array.d.ts +0 -19
  140. package/dist/generated/gobject/value-array.js +0 -70
  141. package/dist/generated/gsk/path.d.ts +1 -41
  142. package/dist/generated/gsk/path.js +0 -96
  143. package/dist/generated/gsk/render-node.d.ts +0 -9
  144. package/dist/generated/gsk/render-node.js +0 -32
  145. package/dist/generated/gst/buffer-list.d.ts +0 -10
  146. package/dist/generated/gst/buffer-list.js +0 -31
  147. package/dist/generated/gst/buffer.d.ts +0 -10
  148. package/dist/generated/gst/buffer.js +0 -31
  149. package/dist/generated/gst/bus.d.ts +0 -43
  150. package/dist/generated/gst/bus.js +0 -88
  151. package/dist/generated/gst/caps.d.ts +0 -26
  152. package/dist/generated/gst/caps.js +0 -89
  153. package/dist/generated/gst/clock.d.ts +0 -15
  154. package/dist/generated/gst/clock.js +0 -35
  155. package/dist/generated/gst/element.d.ts +0 -49
  156. package/dist/generated/gst/element.js +0 -117
  157. package/dist/generated/gst/functions.d.ts +1 -80
  158. package/dist/generated/gst/functions.js +0 -234
  159. package/dist/generated/gst/index.d.ts +0 -1
  160. package/dist/generated/gst/index.js +0 -1
  161. package/dist/generated/gst/iterator.d.ts +0 -56
  162. package/dist/generated/gst/iterator.js +0 -168
  163. package/dist/generated/gst/pad.d.ts +1 -145
  164. package/dist/generated/gst/pad.js +0 -440
  165. package/dist/generated/gst/plugin.d.ts +0 -41
  166. package/dist/generated/gst/plugin.js +0 -132
  167. package/dist/generated/gst/promise.d.ts +0 -9
  168. package/dist/generated/gst/promise.js +1 -27
  169. package/dist/generated/gst/registry.d.ts +0 -21
  170. package/dist/generated/gst/registry.js +0 -73
  171. package/dist/generated/gst/structure.d.ts +0 -52
  172. package/dist/generated/gst/structure.js +0 -178
  173. package/dist/generated/gst/tag-list.d.ts +0 -7
  174. package/dist/generated/gst/tag-list.js +0 -28
  175. package/dist/generated/gst/task-pool.d.ts +0 -6
  176. package/dist/generated/gst/task-pool.js +0 -38
  177. package/dist/generated/gst/type-find.d.ts +0 -15
  178. package/dist/generated/gst/type-find.js +0 -58
  179. package/dist/generated/gstbase/collect-pads.d.ts +0 -108
  180. package/dist/generated/gstbase/collect-pads.js +0 -243
  181. package/dist/generated/gstbase/functions.d.ts +0 -45
  182. package/dist/generated/gstbase/functions.js +0 -132
  183. package/dist/generated/gtk/assistant.d.ts +0 -13
  184. package/dist/generated/gtk/assistant.js +0 -34
  185. package/dist/generated/gtk/builder-cscope.d.ts +0 -13
  186. package/dist/generated/gtk/builder-cscope.js +0 -28
  187. package/dist/generated/gtk/cell-area.d.ts +0 -31
  188. package/dist/generated/gtk/cell-area.js +0 -114
  189. package/dist/generated/gtk/cell-layout.d.ts +0 -14
  190. package/dist/generated/gtk/cell-layout.js +0 -39
  191. package/dist/generated/gtk/cell-view.d.ts +0 -14
  192. package/dist/generated/gtk/cell-view.js +0 -39
  193. package/dist/generated/gtk/combo-box.d.ts +0 -25
  194. package/dist/generated/gtk/combo-box.js +0 -72
  195. package/dist/generated/gtk/drawing-area.d.ts +2 -1
  196. package/dist/generated/gtk/drawing-area.js +6 -1
  197. package/dist/generated/gtk/entry-completion.d.ts +0 -24
  198. package/dist/generated/gtk/entry-completion.js +0 -69
  199. package/dist/generated/gtk/expression.d.ts +0 -14
  200. package/dist/generated/gtk/expression.js +0 -45
  201. package/dist/generated/gtk/flow-box.d.ts +0 -68
  202. package/dist/generated/gtk/flow-box.js +0 -150
  203. package/dist/generated/gtk/font-button.d.ts +0 -8
  204. package/dist/generated/gtk/font-button.js +0 -29
  205. package/dist/generated/gtk/font-chooser-dialog.d.ts +0 -8
  206. package/dist/generated/gtk/font-chooser-dialog.js +0 -29
  207. package/dist/generated/gtk/font-chooser-widget.d.ts +0 -8
  208. package/dist/generated/gtk/font-chooser-widget.js +0 -29
  209. package/dist/generated/gtk/font-chooser.d.ts +0 -8
  210. package/dist/generated/gtk/font-chooser.js +0 -29
  211. package/dist/generated/gtk/functions.d.ts +0 -23
  212. package/dist/generated/gtk/functions.js +0 -69
  213. package/dist/generated/gtk/icon-view.d.ts +0 -21
  214. package/dist/generated/gtk/icon-view.js +0 -62
  215. package/dist/generated/gtk/index.d.ts +0 -7
  216. package/dist/generated/gtk/index.js +0 -7
  217. package/dist/generated/gtk/list-box.d.ts +0 -99
  218. package/dist/generated/gtk/list-box.js +0 -203
  219. package/dist/generated/gtk/list-store.d.ts +0 -33
  220. package/dist/generated/gtk/list-store.js +0 -95
  221. package/dist/generated/gtk/menu-button.d.ts +0 -18
  222. package/dist/generated/gtk/menu-button.js +0 -40
  223. package/dist/generated/gtk/print-job.d.ts +0 -7
  224. package/dist/generated/gtk/print-job.js +0 -27
  225. package/dist/generated/gtk/print-settings.d.ts +0 -6
  226. package/dist/generated/gtk/print-settings.js +0 -22
  227. package/dist/generated/gtk/scale.d.ts +0 -14
  228. package/dist/generated/gtk/scale.js +0 -36
  229. package/dist/generated/gtk/text-buffer.d.ts +0 -19
  230. package/dist/generated/gtk/text-buffer.js +0 -42
  231. package/dist/generated/gtk/text-iter.d.ts +0 -19
  232. package/dist/generated/gtk/text-iter.js +0 -81
  233. package/dist/generated/gtk/text-tag-table.d.ts +0 -9
  234. package/dist/generated/gtk/text-tag-table.js +0 -25
  235. package/dist/generated/gtk/tree-model-filter.d.ts +0 -68
  236. package/dist/generated/gtk/tree-model-filter.js +0 -137
  237. package/dist/generated/gtk/tree-model-sort.d.ts +0 -33
  238. package/dist/generated/gtk/tree-model-sort.js +0 -95
  239. package/dist/generated/gtk/tree-model.d.ts +0 -9
  240. package/dist/generated/gtk/tree-model.js +0 -25
  241. package/dist/generated/gtk/tree-selection.d.ts +0 -20
  242. package/dist/generated/gtk/tree-selection.js +0 -57
  243. package/dist/generated/gtk/tree-sortable.d.ts +0 -24
  244. package/dist/generated/gtk/tree-sortable.js +0 -70
  245. package/dist/generated/gtk/tree-store.d.ts +0 -33
  246. package/dist/generated/gtk/tree-store.js +0 -95
  247. package/dist/generated/gtk/tree-view-column.d.ts +0 -14
  248. package/dist/generated/gtk/tree-view-column.js +0 -39
  249. package/dist/generated/gtk/tree-view.d.ts +0 -54
  250. package/dist/generated/gtk/tree-view.js +0 -167
  251. package/dist/generated/gtk/widget.d.ts +0 -32
  252. package/dist/generated/gtk/widget.js +0 -50
  253. package/dist/generated/gtksource/functions.d.ts +0 -21
  254. package/dist/generated/gtksource/functions.js +0 -49
  255. package/dist/generated/harfbuzz/functions.d.ts +0 -448
  256. package/dist/generated/harfbuzz/functions.js +3736 -5611
  257. package/dist/generated/javascriptcore/class.d.ts +0 -94
  258. package/dist/generated/javascriptcore/class.js +0 -272
  259. package/dist/generated/javascriptcore/context.d.ts +0 -13
  260. package/dist/generated/javascriptcore/context.js +0 -34
  261. package/dist/generated/javascriptcore/functions.d.ts +0 -7
  262. package/dist/generated/javascriptcore/functions.js +0 -19
  263. package/dist/generated/javascriptcore/value.d.ts +0 -72
  264. package/dist/generated/javascriptcore/value.js +0 -202
  265. package/dist/generated/json/array.d.ts +0 -11
  266. package/dist/generated/json/array.js +0 -32
  267. package/dist/generated/json/object.d.ts +0 -14
  268. package/dist/generated/json/object.js +0 -35
  269. package/dist/generated/pango/attr-list.d.ts +0 -8
  270. package/dist/generated/pango/attr-list.js +0 -37
  271. package/dist/generated/pango/fontset.d.ts +0 -9
  272. package/dist/generated/pango/fontset.js +0 -25
  273. package/dist/generated/pango/functions.d.ts +0 -13
  274. package/dist/generated/pango/functions.js +0 -55
  275. package/dist/generated/pangocairo/functions.d.ts +0 -11
  276. package/dist/generated/pangocairo/functions.js +0 -33
  277. package/dist/generated/soup/auth-domain-basic.d.ts +0 -17
  278. package/dist/generated/soup/auth-domain-basic.js +0 -37
  279. package/dist/generated/soup/auth-domain-digest.d.ts +0 -17
  280. package/dist/generated/soup/auth-domain-digest.js +0 -37
  281. package/dist/generated/soup/auth-domain.d.ts +0 -44
  282. package/dist/generated/soup/auth-domain.js +0 -84
  283. package/dist/generated/soup/logger.d.ts +0 -32
  284. package/dist/generated/soup/logger.js +0 -92
  285. package/dist/generated/soup/message-headers.d.ts +0 -17
  286. package/dist/generated/soup/message-headers.js +0 -38
  287. package/dist/generated/soup/server.d.ts +0 -99
  288. package/dist/generated/soup/server.js +0 -184
  289. package/dist/generated/vte/terminal.d.ts +0 -168
  290. package/dist/generated/vte/terminal.js +0 -483
  291. package/dist/generated/webkit/web-context.d.ts +0 -44
  292. package/dist/generated/webkit/web-context.js +0 -68
  293. package/package.json +3 -3
  294. package/dist/generated/adw/callback-animation-target.d.ts +0 -19
  295. package/dist/generated/adw/callback-animation-target.js +0 -64
  296. package/dist/generated/atspi/device-listener.d.ts +0 -26
  297. package/dist/generated/atspi/device-listener.js +0 -104
  298. package/dist/generated/atspi/event-listener.d.ts +0 -155
  299. package/dist/generated/atspi/event-listener.js +0 -496
  300. package/dist/generated/gio/simple-async-result.d.ts +0 -328
  301. package/dist/generated/gio/simple-async-result.js +0 -588
  302. package/dist/generated/gio/task.d.ts +0 -936
  303. package/dist/generated/gio/task.js +0 -1460
  304. package/dist/generated/gst/task.d.ts +0 -128
  305. package/dist/generated/gst/task.js +0 -363
  306. package/dist/generated/gtk/callback-action.d.ts +0 -16
  307. package/dist/generated/gtk/callback-action.js +0 -61
  308. package/dist/generated/gtk/cclosure-expression.d.ts +0 -20
  309. package/dist/generated/gtk/cclosure-expression.js +0 -68
  310. package/dist/generated/gtk/custom-filter.d.ts +0 -35
  311. package/dist/generated/gtk/custom-filter.js +0 -119
  312. package/dist/generated/gtk/custom-layout.d.ts +0 -26
  313. package/dist/generated/gtk/custom-layout.js +0 -71
  314. package/dist/generated/gtk/custom-sorter.d.ts +0 -34
  315. package/dist/generated/gtk/custom-sorter.js +0 -114
  316. package/dist/generated/gtk/map-list-model.d.ts +0 -173
  317. package/dist/generated/gtk/map-list-model.js +0 -361
  318. package/dist/generated/gtk/tree-list-model.d.ts +0 -145
  319. package/dist/generated/gtk/tree-list-model.js +0 -310
@@ -1,936 +0,0 @@
1
- import { AsyncResult } from "./async-result.js";
2
- import { Cancellable } from "./cancellable.js";
3
- import * as GLib from "../glib/index.js";
4
- import * as GObject from "../gobject/index.js";
5
- /**
6
- * A `GTask` represents and manages a cancellable ‘task’.
7
- *
8
- * ## Asynchronous operations
9
- *
10
- * The most common usage of `GTask` is as a [iface@Gio.AsyncResult], to
11
- * manage data during an asynchronous operation. You call
12
- * [ctor@Gio.Task.new] in the ‘start’ method, followed by
13
- * [method@Gio.Task.set_task_data] and the like if you need to keep some
14
- * additional data associated with the task, and then pass the
15
- * task object around through your asynchronous operation.
16
- * Eventually, you will call a method such as
17
- * [method@Gio.Task.return_pointer] or [method@Gio.Task.return_error], which
18
- * will save the value you give it and then invoke the task’s callback
19
- * function in the thread-default main context (see
20
- * [method@GLib.MainContext.push_thread_default])
21
- * where it was created (waiting until the next iteration of the main
22
- * loop first, if necessary). The caller will pass the `GTask` back to
23
- * the operation’s finish function (as a [iface@Gio.AsyncResult]), and you can
24
- * use [method@Gio.Task.propagate_pointer] or the like to extract the
25
- * return value.
26
- *
27
- * Using `GTask` requires the thread-default [struct@GLib.MainContext] from when
28
- * the `GTask` was constructed to be running at least until the task has
29
- * completed and its data has been freed.
30
- *
31
- * If a `GTask` has been constructed and its callback set, it is an error to
32
- * not call `g_task_return_*()` on it. GLib will warn at runtime if this happens
33
- * (since 2.76).
34
- *
35
- * Here is an example for using `GTask` as a [iface@Gio.AsyncResult]:
36
- * ```c
37
- * typedef struct {
38
- * CakeFrostingType frosting;
39
- * char *message;
40
- * } DecorationData;
41
- *
42
- * static void
43
- * decoration_data_free (DecorationData *decoration)
44
- * {
45
- * g_free (decoration->message);
46
- * g_slice_free (DecorationData, decoration);
47
- * }
48
- *
49
- * static void
50
- * baked_cb (Cake *cake,
51
- * gpointer user_data)
52
- * {
53
- * GTask *task = user_data;
54
- * DecorationData *decoration = g_task_get_task_data (task);
55
- * GError *error = NULL;
56
- *
57
- * if (cake == NULL)
58
- * {
59
- * g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
60
- * "Go to the supermarket");
61
- * g_object_unref (task);
62
- * return;
63
- * }
64
- *
65
- * if (!cake_decorate (cake, decoration->frosting, decoration->message, &error))
66
- * {
67
- * g_object_unref (cake);
68
- * // g_task_return_error() takes ownership of error
69
- * g_task_return_error (task, error);
70
- * g_object_unref (task);
71
- * return;
72
- * }
73
- *
74
- * g_task_return_pointer (task, cake, g_object_unref);
75
- * g_object_unref (task);
76
- * }
77
- *
78
- * void
79
- * baker_bake_cake_async (Baker *self,
80
- * guint radius,
81
- * CakeFlavor flavor,
82
- * CakeFrostingType frosting,
83
- * const char *message,
84
- * GCancellable *cancellable,
85
- * GAsyncReadyCallback callback,
86
- * gpointer user_data)
87
- * {
88
- * GTask *task;
89
- * DecorationData *decoration;
90
- * Cake *cake;
91
- *
92
- * task = g_task_new (self, cancellable, callback, user_data);
93
- * if (radius < 3)
94
- * {
95
- * g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_TOO_SMALL,
96
- * "%ucm radius cakes are silly",
97
- * radius);
98
- * g_object_unref (task);
99
- * return;
100
- * }
101
- *
102
- * cake = _baker_get_cached_cake (self, radius, flavor, frosting, message);
103
- * if (cake != NULL)
104
- * {
105
- * // _baker_get_cached_cake() returns a reffed cake
106
- * g_task_return_pointer (task, cake, g_object_unref);
107
- * g_object_unref (task);
108
- * return;
109
- * }
110
- *
111
- * decoration = g_slice_new (DecorationData);
112
- * decoration->frosting = frosting;
113
- * decoration->message = g_strdup (message);
114
- * g_task_set_task_data (task, decoration, (GDestroyNotify) decoration_data_free);
115
- *
116
- * _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
117
- * }
118
- *
119
- * Cake *
120
- * baker_bake_cake_finish (Baker *self,
121
- * GAsyncResult *result,
122
- * GError **error)
123
- * {
124
- * g_return_val_if_fail (g_task_is_valid (result, self), NULL);
125
- *
126
- * return g_task_propagate_pointer (G_TASK (result), error);
127
- * }
128
- * ```
129
- *
130
- * ## Chained asynchronous operations
131
- *
132
- * `GTask` also tries to simplify asynchronous operations that
133
- * internally chain together several smaller asynchronous
134
- * operations. [method@Gio.Task.get_cancellable], [method@Gio.Task.get_context],
135
- * and [method@Gio.Task.get_priority] allow you to get back the task’s
136
- * [class@Gio.Cancellable], [struct@GLib.MainContext], and
137
- * I/O priority
138
- * when starting a new subtask, so you don’t have to keep track
139
- * of them yourself. [method@Gio.Task.attach_source] simplifies the case
140
- * of waiting for a source to fire (automatically using the correct
141
- * [struct@GLib.MainContext] and priority).
142
- *
143
- * Here is an example for chained asynchronous operations:
144
- * ```c
145
- * typedef struct {
146
- * Cake *cake;
147
- * CakeFrostingType frosting;
148
- * char *message;
149
- * } BakingData;
150
- *
151
- * static void
152
- * decoration_data_free (BakingData *bd)
153
- * {
154
- * if (bd->cake)
155
- * g_object_unref (bd->cake);
156
- * g_free (bd->message);
157
- * g_slice_free (BakingData, bd);
158
- * }
159
- *
160
- * static void
161
- * decorated_cb (Cake *cake,
162
- * GAsyncResult *result,
163
- * gpointer user_data)
164
- * {
165
- * GTask *task = user_data;
166
- * GError *error = NULL;
167
- *
168
- * if (!cake_decorate_finish (cake, result, &error))
169
- * {
170
- * g_object_unref (cake);
171
- * g_task_return_error (task, error);
172
- * g_object_unref (task);
173
- * return;
174
- * }
175
- *
176
- * // baking_data_free() will drop its ref on the cake, so we have to
177
- * // take another here to give to the caller.
178
- * g_task_return_pointer (task, g_object_ref (cake), g_object_unref);
179
- * g_object_unref (task);
180
- * }
181
- *
182
- * static gboolean
183
- * decorator_ready (gpointer user_data)
184
- * {
185
- * GTask *task = user_data;
186
- * BakingData *bd = g_task_get_task_data (task);
187
- *
188
- * cake_decorate_async (bd->cake, bd->frosting, bd->message,
189
- * g_task_get_cancellable (task),
190
- * decorated_cb, task);
191
- *
192
- * return G_SOURCE_REMOVE;
193
- * }
194
- *
195
- * static void
196
- * baked_cb (Cake *cake,
197
- * gpointer user_data)
198
- * {
199
- * GTask *task = user_data;
200
- * BakingData *bd = g_task_get_task_data (task);
201
- * GError *error = NULL;
202
- *
203
- * if (cake == NULL)
204
- * {
205
- * g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
206
- * "Go to the supermarket");
207
- * g_object_unref (task);
208
- * return;
209
- * }
210
- *
211
- * bd->cake = cake;
212
- *
213
- * // Bail out now if the user has already cancelled
214
- * if (g_task_return_error_if_cancelled (task))
215
- * {
216
- * g_object_unref (task);
217
- * return;
218
- * }
219
- *
220
- * if (cake_decorator_available (cake))
221
- * decorator_ready (task);
222
- * else
223
- * {
224
- * GSource *source;
225
- *
226
- * source = cake_decorator_wait_source_new (cake);
227
- * // Attach `source` to @task’s GMainContext and have it call
228
- * // decorator_ready() when it is ready.
229
- * g_task_attach_source (task, source, decorator_ready);
230
- * g_source_unref (source);
231
- * }
232
- * }
233
- *
234
- * void
235
- * baker_bake_cake_async (Baker *self,
236
- * guint radius,
237
- * CakeFlavor flavor,
238
- * CakeFrostingType frosting,
239
- * const char *message,
240
- * gint priority,
241
- * GCancellable *cancellable,
242
- * GAsyncReadyCallback callback,
243
- * gpointer user_data)
244
- * {
245
- * GTask *task;
246
- * BakingData *bd;
247
- *
248
- * task = g_task_new (self, cancellable, callback, user_data);
249
- * g_task_set_priority (task, priority);
250
- *
251
- * bd = g_slice_new0 (BakingData);
252
- * bd->frosting = frosting;
253
- * bd->message = g_strdup (message);
254
- * g_task_set_task_data (task, bd, (GDestroyNotify) baking_data_free);
255
- *
256
- * _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
257
- * }
258
- *
259
- * Cake *
260
- * baker_bake_cake_finish (Baker *self,
261
- * GAsyncResult *result,
262
- * GError **error)
263
- * {
264
- * g_return_val_if_fail (g_task_is_valid (result, self), NULL);
265
- *
266
- * return g_task_propagate_pointer (G_TASK (result), error);
267
- * }
268
- * ```
269
- *
270
- * ## Asynchronous operations from synchronous ones
271
- *
272
- * You can use [method@Gio.Task.run_in_thread] to turn a synchronous
273
- * operation into an asynchronous one, by running it in a thread.
274
- * When it completes, the result will be dispatched to the thread-default
275
- * main context (see [method@GLib.MainContext.push_thread_default])
276
- * where the `GTask` was created.
277
- *
278
- * Running a task in a thread:
279
- * ```c
280
- * typedef struct {
281
- * guint radius;
282
- * CakeFlavor flavor;
283
- * CakeFrostingType frosting;
284
- * char *message;
285
- * } CakeData;
286
- *
287
- * static void
288
- * cake_data_free (CakeData *cake_data)
289
- * {
290
- * g_free (cake_data->message);
291
- * g_slice_free (CakeData, cake_data);
292
- * }
293
- *
294
- * static void
295
- * bake_cake_thread (GTask *task,
296
- * gpointer source_object,
297
- * gpointer task_data,
298
- * GCancellable *cancellable)
299
- * {
300
- * Baker *self = source_object;
301
- * CakeData *cake_data = task_data;
302
- * Cake *cake;
303
- * GError *error = NULL;
304
- *
305
- * cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
306
- * cake_data->frosting, cake_data->message,
307
- * cancellable, &error);
308
- * if (cake)
309
- * g_task_return_pointer (task, cake, g_object_unref);
310
- * else
311
- * g_task_return_error (task, error);
312
- * }
313
- *
314
- * void
315
- * baker_bake_cake_async (Baker *self,
316
- * guint radius,
317
- * CakeFlavor flavor,
318
- * CakeFrostingType frosting,
319
- * const char *message,
320
- * GCancellable *cancellable,
321
- * GAsyncReadyCallback callback,
322
- * gpointer user_data)
323
- * {
324
- * CakeData *cake_data;
325
- * GTask *task;
326
- *
327
- * cake_data = g_slice_new (CakeData);
328
- * cake_data->radius = radius;
329
- * cake_data->flavor = flavor;
330
- * cake_data->frosting = frosting;
331
- * cake_data->message = g_strdup (message);
332
- * task = g_task_new (self, cancellable, callback, user_data);
333
- * g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
334
- * g_task_run_in_thread (task, bake_cake_thread);
335
- * g_object_unref (task);
336
- * }
337
- *
338
- * Cake *
339
- * baker_bake_cake_finish (Baker *self,
340
- * GAsyncResult *result,
341
- * GError **error)
342
- * {
343
- * g_return_val_if_fail (g_task_is_valid (result, self), NULL);
344
- *
345
- * return g_task_propagate_pointer (G_TASK (result), error);
346
- * }
347
- * ```
348
- *
349
- * ## Adding cancellability to uncancellable tasks
350
- *
351
- * Finally, [method@Gio.Task.run_in_thread] and
352
- * [method@Gio.Task.run_in_thread_sync] can be used to turn an uncancellable
353
- * operation into a cancellable one. If you call
354
- * [method@Gio.Task.set_return_on_cancel], passing `TRUE`, then if the task’s
355
- * [class@Gio.Cancellable] is cancelled, it will return control back to the
356
- * caller immediately, while allowing the task thread to continue running in the
357
- * background (and simply discarding its result when it finally does finish).
358
- * Provided that the task thread is careful about how it uses
359
- * locks and other externally-visible resources, this allows you
360
- * to make ‘GLib-friendly’ asynchronous and cancellable
361
- * synchronous variants of blocking APIs.
362
- *
363
- * Cancelling a task:
364
- * ```c
365
- * static void
366
- * bake_cake_thread (GTask *task,
367
- * gpointer source_object,
368
- * gpointer task_data,
369
- * GCancellable *cancellable)
370
- * {
371
- * Baker *self = source_object;
372
- * CakeData *cake_data = task_data;
373
- * Cake *cake;
374
- * GError *error = NULL;
375
- *
376
- * cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
377
- * cake_data->frosting, cake_data->message,
378
- * &error);
379
- * if (error)
380
- * {
381
- * g_task_return_error (task, error);
382
- * return;
383
- * }
384
- *
385
- * // If the task has already been cancelled, then we don’t want to add
386
- * // the cake to the cake cache. Likewise, we don’t want to have the
387
- * // task get cancelled in the middle of updating the cache.
388
- * // g_task_set_return_on_cancel() will return %TRUE here if it managed
389
- * // to disable return-on-cancel, or %FALSE if the task was cancelled
390
- * // before it could.
391
- * if (g_task_set_return_on_cancel (task, FALSE))
392
- * {
393
- * // If the caller cancels at this point, their
394
- * // GAsyncReadyCallback won’t be invoked until we return,
395
- * // so we don’t have to worry that this code will run at
396
- * // the same time as that code does. But if there were
397
- * // other functions that might look at the cake cache,
398
- * // then we’d probably need a GMutex here as well.
399
- * baker_add_cake_to_cache (baker, cake);
400
- * g_task_return_pointer (task, cake, g_object_unref);
401
- * }
402
- * }
403
- *
404
- * void
405
- * baker_bake_cake_async (Baker *self,
406
- * guint radius,
407
- * CakeFlavor flavor,
408
- * CakeFrostingType frosting,
409
- * const char *message,
410
- * GCancellable *cancellable,
411
- * GAsyncReadyCallback callback,
412
- * gpointer user_data)
413
- * {
414
- * CakeData *cake_data;
415
- * GTask *task;
416
- *
417
- * cake_data = g_slice_new (CakeData);
418
- *
419
- * ...
420
- *
421
- * task = g_task_new (self, cancellable, callback, user_data);
422
- * g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
423
- * g_task_set_return_on_cancel (task, TRUE);
424
- * g_task_run_in_thread (task, bake_cake_thread);
425
- * }
426
- *
427
- * Cake *
428
- * baker_bake_cake_sync (Baker *self,
429
- * guint radius,
430
- * CakeFlavor flavor,
431
- * CakeFrostingType frosting,
432
- * const char *message,
433
- * GCancellable *cancellable,
434
- * GError **error)
435
- * {
436
- * CakeData *cake_data;
437
- * GTask *task;
438
- * Cake *cake;
439
- *
440
- * cake_data = g_slice_new (CakeData);
441
- *
442
- * ...
443
- *
444
- * task = g_task_new (self, cancellable, NULL, NULL);
445
- * g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
446
- * g_task_set_return_on_cancel (task, TRUE);
447
- * g_task_run_in_thread_sync (task, bake_cake_thread);
448
- *
449
- * cake = g_task_propagate_pointer (task, error);
450
- * g_object_unref (task);
451
- * return cake;
452
- * }
453
- * ```
454
- *
455
- * ## Porting from [class@Gio.SimpleAsyncResult]
456
- *
457
- * `GTask`’s API attempts to be simpler than [class@Gio.SimpleAsyncResult]’s
458
- * in several ways:
459
- *
460
- * - You can save task-specific data with [method@Gio.Task.set_task_data], and
461
- * retrieve it later with [method@Gio.Task.get_task_data]. This replaces the
462
- * abuse of [method@Gio.SimpleAsyncResult.set_op_res_gpointer] for the same
463
- * purpose with [class@Gio.SimpleAsyncResult].
464
- * - In addition to the task data, `GTask` also keeps track of the
465
- * priority, [class@Gio.Cancellable],
466
- * and [struct@GLib.MainContext] associated with the task, so tasks that
467
- * consist of a chain of simpler asynchronous operations will have easy access
468
- * to those values when starting each sub-task.
469
- * - [method@Gio.Task.return_error_if_cancelled] provides simplified
470
- * handling for cancellation. In addition, cancellation
471
- * overrides any other `GTask` return value by default, like
472
- * [class@Gio.SimpleAsyncResult] does when
473
- * [method@Gio.SimpleAsyncResult.set_check_cancellable] is called.
474
- * (You can use [method@Gio.Task.set_check_cancellable] to turn off that
475
- * behavior.) On the other hand, [method@Gio.Task.run_in_thread]
476
- * guarantees that it will always run your
477
- * `task_func`, even if the task’s [class@Gio.Cancellable]
478
- * is already cancelled before the task gets a chance to run;
479
- * you can start your `task_func` with a
480
- * [method@Gio.Task.return_error_if_cancelled] check if you need the
481
- * old behavior.
482
- * - The ‘return’ methods (eg, [method@Gio.Task.return_pointer])
483
- * automatically cause the task to be ‘completed’ as well, and
484
- * there is no need to worry about the ‘complete’ vs ‘complete in idle’
485
- * distinction. (`GTask` automatically figures out
486
- * whether the task’s callback can be invoked directly, or
487
- * if it needs to be sent to another [struct@GLib.MainContext], or delayed
488
- * until the next iteration of the current [struct@GLib.MainContext].)
489
- * - The ‘finish’ functions for `GTask` based operations are generally
490
- * much simpler than [class@Gio.SimpleAsyncResult] ones, normally consisting
491
- * of only a single call to [method@Gio.Task.propagate_pointer] or the like.
492
- * Since [method@Gio.Task.propagate_pointer] ‘steals’ the return value from
493
- * the `GTask`, it is not necessary to juggle pointers around to
494
- * prevent it from being freed twice.
495
- * - With [class@Gio.SimpleAsyncResult], it was common to call
496
- * [method@Gio.SimpleAsyncResult.propagate_error] from the
497
- * `_finish()` wrapper function, and have
498
- * virtual method implementations only deal with successful
499
- * returns. This behavior is deprecated, because it makes it
500
- * difficult for a subclass to chain to a parent class’s async
501
- * methods. Instead, the wrapper function should just be a
502
- * simple wrapper, and the virtual method should call an
503
- * appropriate `g_task_propagate_` function.
504
- * Note that wrapper methods can now use
505
- * [method@Gio.AsyncResult.legacy_propagate_error] to do old-style
506
- * [class@Gio.SimpleAsyncResult] error-returning behavior, and
507
- * [method@Gio.AsyncResult.is_tagged] to check if a result is tagged as
508
- * having come from the `_async()` wrapper
509
- * function (for ‘short-circuit’ results, such as when passing
510
- * `0` to [method@Gio.InputStream.read_async]).
511
- *
512
- * ## Thread-safety considerations
513
- *
514
- * Due to some infelicities in the API design, there is a
515
- * thread-safety concern that users of `GTask` have to be aware of:
516
- *
517
- * If the `main` thread drops its last reference to the source object
518
- * or the task data before the task is finalized, then the finalizers
519
- * of these objects may be called on the worker thread.
520
- *
521
- * This is a problem if the finalizers use non-threadsafe API, and
522
- * can lead to hard-to-debug crashes. Possible workarounds include:
523
- *
524
- * - Clear task data in a signal handler for `notify::completed`
525
- * - Keep iterating a main context in the main thread and defer
526
- * dropping the reference to the source object to that main
527
- * context when the task is finalized
528
- */
529
- export declare class Task extends GObject.GObject {
530
- static readonly glibTypeName: string;
531
- /**
532
- * Creates a #GTask acting on @source_object, which will eventually be
533
- * used to invoke `callback` in the current thread-default main context
534
- * (see [method@GLib.MainContext.push_thread_default]).
535
- *
536
- * Call this in the "start" method of your asynchronous method, and
537
- * pass the #GTask around throughout the asynchronous operation. You
538
- * can use g_task_set_task_data() to attach task-specific data to the
539
- * object, which you can retrieve later via g_task_get_task_data().
540
- *
541
- * By default, if `cancellable` is cancelled, then the return value of
542
- * the task will always be %G_IO_ERROR_CANCELLED, even if the task had
543
- * already completed before the cancellation. This allows for
544
- * simplified handling in cases where cancellation may imply that
545
- * other objects that the task depends on have been destroyed. If you
546
- * do not want this behavior, you can use
547
- * g_task_set_check_cancellable() to change it.
548
- * @param sourceObject - the #GObject that owns
549
- * @param cancellable - optional #GCancellable object, %NULL to ignore.
550
- * @param callback - a #GAsyncReadyCallback.
551
- * @param callbackData - user data passed to @callback.
552
- */
553
- constructor(sourceObject?: GObject.GObject | null, cancellable?: Cancellable | null, callback?: (...args: unknown[]) => unknown | null, callbackData?: number | null);
554
- /**
555
- * Checks that `result` is a #GTask, and that `source_object` is its
556
- * source object (or that `source_object` is %NULL and `result` has no
557
- * source object). This can be used in g_return_if_fail() checks.
558
- * @param result - A #GAsyncResult
559
- * @param sourceObject - the source object
560
- */
561
- static isValid(result: AsyncResult, sourceObject?: GObject.GObject | null): boolean;
562
- /**
563
- * Creates a #GTask and then immediately calls g_task_return_error()
564
- * on it. Use this in the wrapper function of an asynchronous method
565
- * when you want to avoid even calling the virtual method. You can
566
- * then use g_async_result_is_tagged() in the finish method wrapper to
567
- * check if the result there is tagged as having been created by the
568
- * wrapper method, and deal with it appropriately if so.
569
- *
570
- * See also g_task_report_new_error().
571
- * @param sourceObject - the #GObject that owns
572
- * @param callback - a #GAsyncReadyCallback.
573
- * @param callbackData - user data passed to @callback.
574
- * @param sourceTag - an opaque pointer indicating the source of this task
575
- * @param error - error to report
576
- */
577
- static reportError(error: GLib.GError, sourceObject?: GObject.GObject | null, callback?: (...args: unknown[]) => unknown | null, callbackData?: number | null, sourceTag?: number | null): void;
578
- /**
579
- * Gets @task's #GCancellable
580
- */
581
- getCancellable(): Cancellable | null;
582
- /**
583
- * Gets @task's check-cancellable flag. See
584
- * g_task_set_check_cancellable() for more details.
585
- */
586
- getCheckCancellable(): boolean;
587
- /**
588
- * Gets the value of #GTask:completed. This changes from %FALSE to %TRUE after
589
- * the task’s callback is invoked, and will return %FALSE if called from inside
590
- * the callback.
591
- */
592
- getCompleted(): boolean;
593
- /**
594
- * Gets the #GMainContext that `task` will return its result in (that
595
- * is, the context that was the thread-default main context
596
- * (see [method@GLib.MainContext.push_thread_default])
597
- * at the point when `task` was created).
598
- *
599
- * This will always return a non-%NULL value, even if the task's
600
- * context is the default #GMainContext.
601
- */
602
- getContext(): GLib.MainContext;
603
- /**
604
- * Gets @task’s name. See g_task_set_name().
605
- */
606
- getName(): string | null;
607
- /**
608
- * Gets @task's priority
609
- */
610
- getPriority(): number;
611
- /**
612
- * Gets @task's return-on-cancel flag. See
613
- * g_task_set_return_on_cancel() for more details.
614
- */
615
- getReturnOnCancel(): boolean;
616
- /**
617
- * Gets the source object from @task. Like
618
- * g_async_result_get_source_object(), but does not ref the object.
619
- */
620
- getSourceObject(): GObject.GObject | null;
621
- /**
622
- * Gets @task's source tag. See g_task_set_source_tag().
623
- */
624
- getSourceTag(): number | null;
625
- /**
626
- * Gets @task's `task_data`.
627
- */
628
- getTaskData(): number | null;
629
- /**
630
- * Tests if `task` resulted in an error.
631
- */
632
- hadError(): boolean;
633
- /**
634
- * Gets the result of `task` as a #gboolean.
635
- *
636
- * If the task resulted in an error, or was cancelled, then this will
637
- * instead return %FALSE and set @error.
638
- *
639
- * Since this method transfers ownership of the return value (or
640
- * error) to the caller, you may only call it once.
641
- */
642
- propagateBoolean(): boolean;
643
- /**
644
- * Gets the result of `task` as an integer (#gssize).
645
- *
646
- * If the task resulted in an error, or was cancelled, then this will
647
- * instead return -1 and set @error.
648
- *
649
- * Since this method transfers ownership of the return value (or
650
- * error) to the caller, you may only call it once.
651
- */
652
- propagateInt(): number;
653
- /**
654
- * Gets the result of `task` as a pointer, and transfers ownership
655
- * of that value to the caller.
656
- *
657
- * If the task resulted in an error, or was cancelled, then this will
658
- * instead return %NULL and set @error.
659
- *
660
- * Since this method transfers ownership of the return value (or
661
- * error) to the caller, you may only call it once.
662
- */
663
- propagatePointer(): number | null;
664
- /**
665
- * Gets the result of `task` as a #GValue, and transfers ownership of
666
- * that value to the caller. As with g_task_return_value(), this is
667
- * a generic low-level method; g_task_propagate_pointer() and the like
668
- * will usually be more useful for C code.
669
- *
670
- * If the task resulted in an error, or was cancelled, then this will
671
- * instead set `error` and return %FALSE.
672
- *
673
- * Since this method transfers ownership of the return value (or
674
- * error) to the caller, you may only call it once.
675
- * @param value - return location for the #GValue
676
- */
677
- propagateValue(value: GObject.Value): boolean;
678
- /**
679
- * Sets @task's result to `result` and completes the task (see
680
- * g_task_return_pointer() for more discussion of exactly what this
681
- * means).
682
- * @param result - the #gboolean result of a task function.
683
- */
684
- returnBoolean(result: boolean): void;
685
- /**
686
- * Sets @task's result to `error` (which `task` assumes ownership of)
687
- * and completes the task (see g_task_return_pointer() for more
688
- * discussion of exactly what this means).
689
- *
690
- * Note that since the task takes ownership of @error, and since the
691
- * task may be completed before returning from g_task_return_error(),
692
- * you cannot assume that `error` is still valid after calling this.
693
- * Call g_error_copy() on the error if you need to keep a local copy
694
- * as well.
695
- *
696
- * See also [method@Gio.Task.return_new_error],
697
- * [method@Gio.Task.return_new_error_literal].
698
- * @param error - the #GError result of a task function.
699
- */
700
- returnError(error: GLib.GError): void;
701
- /**
702
- * Checks if @task's #GCancellable has been cancelled, and if so, sets
703
- * @task's error accordingly and completes the task (see
704
- * g_task_return_pointer() for more discussion of exactly what this
705
- * means).
706
- */
707
- returnErrorIfCancelled(): boolean;
708
- /**
709
- * Sets @task's result to `result` and completes the task (see
710
- * g_task_return_pointer() for more discussion of exactly what this
711
- * means).
712
- * @param result - the integer (#gssize) result of a task function.
713
- */
714
- returnInt(result: number): void;
715
- /**
716
- * Sets @task’s result to a new [type@GLib.Error] created from @domain, @code,
717
- * `message` and completes the task.
718
- *
719
- * See [method@Gio.Task.return_pointer] for more discussion of exactly what
720
- * ‘completing the task’ means.
721
- *
722
- * See also [method@Gio.Task.return_new_error].
723
- * @param domain - a #GQuark.
724
- * @param code - an error code.
725
- * @param message - an error message
726
- */
727
- returnNewErrorLiteral(domain: number, code: number, message: string): void;
728
- /**
729
- * Sets @task's result to `result` and completes the task. If `result` is not %NULL, then `result_destroy` will be used to free `result` if
730
- * the caller does not take ownership of it with
731
- * g_task_propagate_pointer().
732
- *
733
- * "Completes the task" means that for an ordinary asynchronous task
734
- * it will either invoke the task's callback, or else queue that
735
- * callback to be invoked in the proper #GMainContext, or in the next
736
- * iteration of the current #GMainContext. For a task run via
737
- * g_task_run_in_thread() or g_task_run_in_thread_sync(), calling this
738
- * method will save `result` to be returned to the caller later, but
739
- * the task will not actually be completed until the #GTaskThreadFunc
740
- * exits.
741
- *
742
- * Note that since the task may be completed before returning from
743
- * g_task_return_pointer(), you cannot assume that `result` is still
744
- * valid after calling this, unless you are still holding another
745
- * reference on it.
746
- * @param result - the pointer result of a task
747
- * @param resultDestroy - a #GDestroyNotify function.
748
- */
749
- returnPointer(result?: number | null, resultDestroy?: () => void | null): void;
750
- /**
751
- * Sets @task's result to `result` (by copying it) and completes the task.
752
- *
753
- * If `result` is %NULL then a #GValue of type %G_TYPE_POINTER
754
- * with a value of %NULL will be used for the result.
755
- *
756
- * This is a very generic low-level method intended primarily for use
757
- * by language bindings; for C code, g_task_return_pointer() and the
758
- * like will normally be much easier to use.
759
- * @param result - the #GValue result of
760
- */
761
- returnValue(result?: GObject.Value | null): void;
762
- /**
763
- * Runs `task_func` in another thread. When `task_func` returns, @task's
764
- * #GAsyncReadyCallback will be invoked in @task's #GMainContext.
765
- *
766
- * This takes a ref on `task` until the task completes.
767
- *
768
- * See #GTaskThreadFunc for more details about how `task_func` is handled.
769
- *
770
- * Although GLib currently rate-limits the tasks queued via
771
- * g_task_run_in_thread(), you should not assume that it will always
772
- * do this. If you have a very large number of tasks to run (several tens of
773
- * tasks), but don't want them to all run at once, you should only queue a
774
- * limited number of them (around ten) at a time.
775
- *
776
- * Be aware that if your task depends on other tasks to complete, use of this
777
- * function could lead to a livelock if the other tasks also use this function
778
- * and enough of them (around 10) execute in a dependency chain, as that will
779
- * exhaust the thread pool. If this situation is possible, consider using a
780
- * separate worker thread or thread pool explicitly, rather than using
781
- * g_task_run_in_thread().
782
- * @param taskFunc - a #GTaskThreadFunc
783
- */
784
- runInThread(taskFunc: (...args: unknown[]) => unknown): void;
785
- /**
786
- * Runs `task_func` in another thread, and waits for it to return or be
787
- * cancelled. You can use g_task_propagate_pointer(), etc, afterward
788
- * to get the result of @task_func.
789
- *
790
- * See #GTaskThreadFunc for more details about how `task_func` is handled.
791
- *
792
- * Normally this is used with tasks created with a %NULL
793
- * `callback`, but note that even if the task does
794
- * have a callback, it will not be invoked when `task_func` returns.
795
- * #GTask:completed will be set to %TRUE just before this function returns.
796
- *
797
- * Although GLib currently rate-limits the tasks queued via
798
- * g_task_run_in_thread_sync(), you should not assume that it will
799
- * always do this. If you have a very large number of tasks to run,
800
- * but don't want them to all run at once, you should only queue a
801
- * limited number of them at a time.
802
- * @param taskFunc - a #GTaskThreadFunc
803
- */
804
- runInThreadSync(taskFunc: (...args: unknown[]) => unknown): void;
805
- /**
806
- * Sets or clears @task's check-cancellable flag. If this is %TRUE
807
- * (the default), then g_task_propagate_pointer(), etc, and
808
- * g_task_had_error() will check the task's #GCancellable first, and
809
- * if it has been cancelled, then they will consider the task to have
810
- * returned an "Operation was cancelled" error
811
- * (%G_IO_ERROR_CANCELLED), regardless of any other error or return
812
- * value the task may have had.
813
- *
814
- * If `check_cancellable` is %FALSE, then the #GTask will not check the
815
- * cancellable itself, and it is up to @task's owner to do this (eg,
816
- * via g_task_return_error_if_cancelled()).
817
- *
818
- * If you are using g_task_set_return_on_cancel() as well, then
819
- * you must leave check-cancellable set %TRUE.
820
- * @param checkCancellable - whether #GTask will check the state of
821
- */
822
- setCheckCancellable(checkCancellable: boolean): void;
823
- /**
824
- * Sets @task’s name, used in debugging and profiling. The name defaults to
825
- * %NULL.
826
- *
827
- * The task name should describe in a human readable way what the task does.
828
- * For example, ‘Open file’ or ‘Connect to network host’. It is used to set the
829
- * name of the #GSource used for idle completion of the task.
830
- *
831
- * This function may only be called before the `task` is first used in a thread
832
- * other than the one it was constructed in.
833
- * @param name - a human readable name for the task, or %NULL to unset it
834
- */
835
- setName(name?: string | null): void;
836
- /**
837
- * Sets @task's priority. If you do not call this, it will default to
838
- * %G_PRIORITY_DEFAULT.
839
- *
840
- * This will affect the priority of #GSources created with
841
- * g_task_attach_source() and the scheduling of tasks run in threads,
842
- * and can also be explicitly retrieved later via
843
- * g_task_get_priority().
844
- * @param priority - the priority of the request
845
- */
846
- setPriority(priority: number): void;
847
- /**
848
- * Sets or clears @task's return-on-cancel flag. This is only
849
- * meaningful for tasks run via g_task_run_in_thread() or
850
- * g_task_run_in_thread_sync().
851
- *
852
- * If `return_on_cancel` is %TRUE, then cancelling @task's
853
- * #GCancellable will immediately cause it to return, as though the
854
- * task's #GTaskThreadFunc had called
855
- * g_task_return_error_if_cancelled() and then returned.
856
- *
857
- * This allows you to create a cancellable wrapper around an
858
- * uninterruptible function. The #GTaskThreadFunc just needs to be
859
- * careful that it does not modify any externally-visible state after
860
- * it has been cancelled. To do that, the thread should call
861
- * g_task_set_return_on_cancel() again to (atomically) set
862
- * return-on-cancel %FALSE before making externally-visible changes;
863
- * if the task gets cancelled before the return-on-cancel flag could
864
- * be changed, g_task_set_return_on_cancel() will indicate this by
865
- * returning %FALSE.
866
- *
867
- * You can disable and re-enable this flag multiple times if you wish.
868
- * If the task's #GCancellable is cancelled while return-on-cancel is
869
- * %FALSE, then calling g_task_set_return_on_cancel() to set it %TRUE
870
- * again will cause the task to be cancelled at that point.
871
- *
872
- * If the task's #GCancellable is already cancelled before you call
873
- * g_task_run_in_thread()/g_task_run_in_thread_sync(), then the
874
- * #GTaskThreadFunc will still be run (for consistency), but the task
875
- * will also be completed right away.
876
- * @param returnOnCancel - whether the task returns automatically when
877
- */
878
- setReturnOnCancel(returnOnCancel: boolean): boolean;
879
- /**
880
- * Sets @task's source tag.
881
- *
882
- * You can use this to tag a task return
883
- * value with a particular pointer (usually a pointer to the function
884
- * doing the tagging) and then later check it using
885
- * g_task_get_source_tag() (or g_async_result_is_tagged()) in the
886
- * task's "finish" function, to figure out if the response came from a
887
- * particular place.
888
- *
889
- * A macro wrapper around this function will automatically set the
890
- * task’s name to the string form of `source_tag` if it’s not already
891
- * set, for convenience.
892
- * @param sourceTag - an opaque pointer indicating the source of this task
893
- */
894
- setSourceTag(sourceTag?: number | null): void;
895
- /**
896
- * Sets @task’s name, used in debugging and profiling.
897
- *
898
- * This is a variant of g_task_set_name() that avoids copying @name.
899
- *
900
- * This function is called automatically by [method@Gio.Task.set_source_tag]
901
- * unless a name is set.
902
- * @param name - a human readable name for the task. Must be a string literal
903
- */
904
- setStaticName(name?: string | null): void;
905
- /**
906
- * Sets @task's task data (freeing the existing task data, if any).
907
- * @param taskData - task-specific data
908
- * @param taskDataDestroy - #GDestroyNotify for @task_data
909
- */
910
- setTaskData(taskData?: number | null, taskDataDestroy?: () => void | null): void;
911
- /**
912
- * Gets the user data from a [iface@Gio.AsyncResult].
913
- */
914
- getUserData(): number | null;
915
- /**
916
- * Checks if `res` has the given `source_tag` (generally a function
917
- * pointer indicating the function `res` was created by).
918
- * @param sourceTag - an application-defined tag
919
- */
920
- isTagged(sourceTag?: number | null): boolean;
921
- /**
922
- * If `res` is a [class@Gio.SimpleAsyncResult], this is equivalent to
923
- * [method@Gio.SimpleAsyncResult.propagate_error]. Otherwise it returns
924
- * `FALSE`.
925
- *
926
- * This can be used for legacy error handling in async `*_finish()`
927
- * wrapper functions that traditionally handled [class@Gio.SimpleAsyncResult]
928
- * error returns themselves rather than calling into the virtual method.
929
- * This should not be used in new code; [iface@Gio.AsyncResult] errors that are
930
- * set by virtual methods should also be extracted by virtual methods,
931
- * to enable subclasses to chain up correctly.
932
- */
933
- legacyPropagateError(): boolean;
934
- connect(signal: "notify", handler: (self: Task, pspec: GObject.ParamSpec) => void, after?: boolean): number;
935
- connect(signal: string, handler: (...args: any[]) => any, after?: boolean): number;
936
- }