Fuzion Logo
fuzion-lang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.

net/connections.fz


# This file is part of the Fuzion language implementation.
#
# The Fuzion language implementation is free software: you can redistribute it
# and/or modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation, version 3 of the License.
#
# The Fuzion language implementation is distributed in the hope that it will be
# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License along with The
# Fuzion language implementation.  If not, see <https://www.gnu.org/licenses/>.


# -----------------------------------------------------------------------
#
#  Tokiwa Software GmbH, Germany
#
#  Source code of Fuzion standard library feature connections
#
# -----------------------------------------------------------------------

# effect to hold active connections
#
module:public connections(active container.Set i32) : effect is

  # add to active connections
  #
  module add(desc i32) =>
    connections (active.union (container.set_of_ordered [desc]))
      .replace


  # close connection manually.
  # note that connections are closed automatically
  # when effect is uninstalled, i.e. on abort or when thread is finished.
  #
  module close(desc i32) =>
    connections (active.difference (container.set_of_ordered [desc]))
      .replace
    fuzion.sys.net.close desc # NYI: handle errors


  module is_active(desc i32) => active.contains desc


  # cleanup active connections that
  # have not been closed manually
  #
  public redef finally unit =>
    active
      .map desc->
        fuzion.sys.net.close desc
      .for_each res->
        match res
          e error => fuzion.runtime.fault.cause ("net.connections.finally", "closing connection failed: {e}")
          unit =>


# short-hand to get connections effect
#
public connections net.connections =>
  if !net.connections.is_instated
    (connections (container.set_of_ordered i32 [])).default
  net.connections.env

last changed: 2025-07-10