Commit Graph

76 Commits

Author SHA1 Message Date
jike
e72caf7b45 multi: remove x/exp/maps dependency 2025-03-25 10:34:19 +08:00
jike
796110f7af fn: remove x/exp dependency 2025-03-17 16:43:38 +08:00
Boris Nagaev
07c46680e9 fn/ContextGuard: use context.AfterFunc to wait
Simplifies context cancellation handling by using context.AfterFunc instead of a
goroutine to wait for context cancellation. This approach avoids the overhead of
a goroutine during the waiting period.

For ctxQuitUnsafe, since g.quit is closed only in the Quit method (which also
cancels all associated contexts), waiting on context cancellation ensures the
same behavior without unnecessary dependency on g.quit.

Added a test to ensure that the Create method does not launch any goroutines.
2025-01-02 10:38:26 -03:00
Boris Nagaev
e9ab603735 fn/ContextGuard: clear store of cancel funcs
If ContextGuard lives for some time after Quit method is called, the map won't
be collected by GC. Optimization.
2025-01-02 10:38:26 -03:00
Boris Nagaev
1750aec13d fn: remove uneeded argument of ctxBlocking
Removed 'cancel' argument, because it is called only in case the context has
already expired and the only action that cancel function did was cancelling the
context.
2025-01-02 10:38:26 -03:00
Boris Nagaev
865da9c525 fn/ContextGuard: test cancelling blocking context
Make sure WgWait() doesn't block.
2025-01-02 10:38:26 -03:00
Eugene Siegel
6fb8269c84 fn: add set copy method Copy 2024-12-18 15:17:23 -05:00
Oliver Gugger
729cd22bf6 Merge pull request #8914 from z017/master
fn: add synchronous write file
2024-12-16 18:39:52 +01:00
z017
0652cbd4a1 fn: add synchronous write file
The fn.WriteFile writes data like os.WriteFile but in sync mode.
Also adds a behaviour flag that enables removal of file on error.

Co-authored-by: Maurice Poirrier Chuden <mauricepoirrier@gmail.com>
Co-authored-by: Greg Weber <1183+gregwebs@users.noreply.github.com>
2024-12-16 11:16:00 -03:00
Elle Mouton
f99cabf7b4 fn: rework the ContextGuard and add tests
In this commit, the ContextGuard struct is re-worked such that the
context that its new main WithCtx method provides is cancelled in sync
with a parent context being cancelled or with it's quit channel being
cancelled. Tests are added to assert the behaviour. In order for the
close of the quit channel to be consistent with the cancelling of the
derived context, the quit channel _must_ be contained internal to the
ContextGuard so that callers are only able to close the channel via the
exposed Quit method which will then take care to first cancel any
derived context that depend on the quit channel before returning.
2024-12-13 10:44:03 +02:00
Elle Mouton
c2165c4ede fn: add Guard test helper
Copied from lightninglabs/loop
2024-12-13 10:44:03 +02:00
Elle Mouton
51eeb9ece3 fn: Remove ctx from GoroutineManager constructor 2024-12-12 09:32:57 +02:00
ziggie
e8ee087cbc fn: add deep copy interface. 2024-12-10 14:10:33 +01:00
Keagan McClelland
a3e87cfebd fn: update fn/go.mod to v2 2024-11-20 10:28:55 -07:00
Boris Nagaev
891e9621d7 fn: GoroutineManager.Go returns bool, not error
This was requested in https://github.com/lightningnetwork/lnd/pull/9140#discussion_r1821181787
2024-11-14 15:03:25 -03:00
Boris Nagaev
669ebf49d4 fn: stress test GoroutineManager.Stop calls
Make sure there is no race condition between Done() and Wait() methods in the
GoroutineManager implementation.

See https://github.com/lightningnetwork/lnd/pull/9141#issuecomment-2467726384
2024-11-14 01:13:02 -03:00
Oliver Gugger
f42636fec9 Merge pull request #8985 from ProofOfKeags/fn/collect-results
fn: more fn goodies
2024-11-07 18:50:57 +01:00
Keagan McClelland
9f35664a12 fn: breaking - make or else functions accept error argument 2024-11-06 17:32:59 -07:00
Keagan McClelland
dd7f1569c7 fn: breaking - rename ChainOption to FlatMapOption for consistency 2024-11-06 17:32:59 -07:00
Keagan McClelland
5e947046a3 fn: breaking - give Result's FlatMap proper functor annotation 2024-11-06 17:32:59 -07:00
Keagan McClelland
4d16d5ff15 fn: breaking - replace AndThen2 with more principled LiftA2Result 2024-11-06 17:32:59 -07:00
Keagan McClelland
1480287cfc fn: breaking - improve naming of option api functions 2024-11-06 17:32:59 -07:00
Keagan McClelland
be50dd9acb fn: breaking - remove deprecated Result functions 2024-11-06 17:32:59 -07:00
Keagan McClelland
1805fd6f19 fn: breaking - polish Either API 2024-11-06 17:32:58 -07:00
Keagan McClelland
c6734ea013 fn: breaking - reverse argument order in slice funcs 2024-11-06 17:32:50 -07:00
Keagan McClelland
a026d64c1b fn: breaking - fix type variables for better inference 2024-11-06 16:50:06 -07:00
Keagan McClelland
9bbd327a10 fn: add Sink to Result 2024-11-06 16:50:02 -07:00
Keagan McClelland
5dec35426c fn: add transpositions for Option and Result 2024-11-06 16:40:36 -07:00
Keagan McClelland
8971c4c3ae fn: add operations to Result API 2024-11-06 16:40:15 -07:00
Keagan McClelland
5faad77f33 fn: add conversions between Result and Option 2024-11-06 16:39:33 -07:00
Keagan McClelland
a741c54175 fn: add compound slice functions 2024-11-06 16:29:41 -07:00
Keagan McClelland
7a7f3bdb2c fn: fix UnwrapOrFail semantics 2024-11-06 15:55:18 -07:00
ffranr
71298f7614 fn: fix documentation comment for Option
Remove the type generic from the `Option` type struct in the doc
comment.
2024-10-29 20:16:20 +00:00
ffranr
c49d038540 fn: add OptionFromPtr function
Add a function `OptionFromPtr` that constructs an `Option` from a
pointer. The function signature is: `OptionFromPtr : *A -> Option[A]`.

This utility has proven useful in the taproot-assets project.
2024-10-29 20:16:20 +00:00
Oliver Gugger
deefa3a9f1 fn: add ContextGuard from tapd repo
This adds the ContextGuard struct from the taproot-assets repository
that has been in use there for a while.

The context guard allows for easy creation of contexts that depend on a
central wait group and quit channel.

A context can either be created with a timeout and quit, meaning it will
cancel either on reaching the timeout or when the central quit channel
is closed.

Or a context can be created to block and use a timeout, meaning it will
_not_ cancel on quit but rather block the shutdown until it is completed
(or times out).

The third way is to create a context that just cancels on quit with no
timeout.
2024-10-17 13:11:30 +02:00
Olaoluwa Osuntokun
bdc5187749 Merge pull request #9159 from ziggie1984/fn-set-addon
fn: Add Size and IsEmpty methods to Set
2024-10-07 17:30:05 +02:00
Olaoluwa Osuntokun
e2c97ede81 Merge pull request #9141 from starius/goroutines2
fn: add goroutine manager
2024-10-04 19:15:46 -07:00
Keagan McClelland
4e1579cf4c fn: add uncons, unsnoc and its component projections 2024-10-04 14:47:11 -06:00
ziggie
42e8a43375 fn: Add Size and IsEmpty methods to Set 2024-10-04 01:07:47 +02:00
András Bánki-Horváth
9eb405e9c6 fn: add goroutine manager
The package provides type GoroutineManager which is used to launch goroutines
until context expires or the manager is stopped. Stop method blocks until all
started goroutines stop.

Original code by Andras https://go.dev/play/p/HhRpE-K2lA0

Adjustments and tests by Boris.
2024-10-02 20:29:59 -03:00
Keagan McClelland
f7264e6a5b fn: add Filter to List
This commit adds an immutable Filter method to the linked List API.
This is useful because there are several instances wherein we iterate
through the linked List and only process a subset of it in some way
or another.
2024-09-26 14:24:36 -06:00
Keagan McClelland
2c6d229a69 fn: harden and refine the Req[I,O] API.
In this commit we opt to make the internal response channel fully
private and instead expose methods for doing resolution. This
prevents internal implementation details from leaking a little bit
better than the previous iteration.
2024-07-31 12:59:10 -07:00
Keagan McClelland
4835fdf237 fn: Add new Req type to abstract the pattern of remote processing.
It is common throughout the codebase to send data to a remote
goroutine for processing. Typically, along with the data we are
processing, we also send a one-shot channel where we intend to
listen for the response. This type encapsulates that pattern.
2024-07-31 12:59:03 -07:00
Keagan McClelland
eaa5e4a039 fn: remove redundant Reduce function
This commit removes Reduce since we already have both Foldl and Foldr.
2024-07-10 17:06:09 -07:00
Keagan McClelland
fa2e25d5f4 fn: remove lru dependency 2024-07-10 17:06:04 -07:00
Keagan McClelland
364d79e552 fn: add generic version of List 2024-07-10 16:55:29 -07:00
Keagan McClelland
fb1437cb6d fn: add Elem function for set membership 2024-07-10 15:37:27 -07:00
Keagan McClelland
9c30bce10c fn: add curried (in)equality functions 2024-07-10 15:37:27 -07:00
Keagan McClelland
c4df2f1dce fn: reimplement internals of either, add tests 2024-07-10 15:37:27 -07:00
Keagan McClelland
1dd56f1b2a fn: fix and finish the either API 2024-07-10 15:37:27 -07:00