Skip to content

Commit

Permalink
Make the documentation work with DocC.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhx committed Jan 25, 2024
1 parent 063a4f1 commit 78b364a
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions Sources/GIO/SwiftGIOConvenienceAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// GIO
//
// Created by Rene Hexel on 20/6/16.
// Copyright © 2016, 2018, 2019, 2020 Rene Hexel.
// Copyright © 2016, 2018, 2019, 2020, 2024 Rene Hexel.
// All Rights Reserved
//
//
Expand All @@ -12,33 +12,36 @@ import CGLib
import GLib
import GLibObject

//#if os(Linux)
//public struct GNativeSocketAddress {}
//#endif

/// Convenience additions for Cancellables
public extension CancellableProtocol {
/// Convenience function to connect to the #GCancellable::cancelled
/// signal. Also handles the race condition that may happen
/// Convenience method to connect to the ``cancelledSignal``.
///
/// This method also handles the race condition that may happen
/// if the cancellable is cancelled right before connecting.
///
/// @data_destroy_func will be called when the handler is
/// The `dataDestroyFunc` will be called when the handler is
/// disconnected, or immediately if the cancellable is already
/// cancelled.
///
/// @callback is called at most once, either directly at the
/// time of the connect if @cancellable is already cancelled,
/// or when @cancellable is cancelled in some thread.
/// `callback` is called at most once, either directly at the
/// time of the connect if the ``Cancellable`` is already cancelled,
/// or when the ``Cancellable`` is cancelled in some thread.
///
/// See #GCancellable::cancelled for details on how to use this.
/// See ``isCancelled`` for details on how to use this.
///
/// Since GLib 2.40, the lock protecting @cancellable is not held when
/// @callback is invoked. This lifts a restriction in place for
/// earlier GLib versions which now makes it easier to write cleanup
/// code that unconditionally invokes e.g. g_cancellable_cancel().
func connect<T>(data: UnsafePointer<T>? = nil, dataDestroyFunc: GLib.DestroyNotify? = nil, callback c: @escaping GLibObject.Callback) -> Int {
/// Since GLib 2.40, the lock protecting the ``Cancellable`` is not held when
/// `callback` is invoked. This lifts a restriction in place for
/// earlier GLib versions, which now makes it easier to write cleanup
/// code that unconditionally invokes e.g. ``cancel()``.
/// - Parameters:
/// - data: Pointer to the data to pass to the callback
/// - dataDestroyFunc: Function to call to free the data.
/// - callback: Callback to call when the cancellable is cancelled.
/// - Returns: The handler ID (always greater than 0).
@inlinable
func connect<T>(data: UnsafePointer<T>? = nil, dataDestroyFunc: GLib.DestroyNotify? = nil, callback: @escaping GLibObject.Callback) -> Int {
let d = data.map { UnsafeMutableRawPointer(mutating: $0) } ?? UnsafeMutableRawPointer(ptr)
let f = dataDestroyFunc ?? { _ in }
return connect(callback: c, data: d, dataDestroyFunc: f)
return connect(callback: callback, data: d, dataDestroyFunc: f)
}
}

0 comments on commit 78b364a

Please sign in to comment.