jerelo 4.0.0
jerelo: ^4.0.0 copied to clipboard
A minimal, lawful Dart functional toolkit for composing synchronous and asynchronous workflows using continuation-passing style (CPS).
4.0.0 #
- Breaking:
Cont.bracketreleases before it reports. It runsreleaseafterusereports any outcome and forwards that outcome oncereleasehas finished, liketry/finally. Before, the outcome was forwarded first andreleaseran fire-and-forget. - Breaking:
releasetakes the resource and aBracketOutcomethat says howuseended:ThenBracketOutcome(value),ElseBracketOutcome(error)orCrashBracketOutcome(crash). Changerelease: (r) => ...torelease: (r, _) => ...when the cleanup is the same for every outcome. - Breaking: once
acquirehas given a resource,releasealways runs, including whenusethrows while being built. Ifacquirecrashes there is no resource andreleasedoes not run; its crash is reported as it is. - Breaking: a crash of
releaseis no longer dropped. A crash ofreleasealone replaces a success or an error ofuse; ifusecrashed and thenreleasecrashed too,Cont.bracketreports aMergedCrashof both,usefirst. A throw while buildingreleaseis a crash ofrelease. - Breaking:
Cont.bracketadds no cancellation of its own. A cancel goes to whichever ofacquire,useandreleaseis running.releaseruns afterusereports, so ausethat is cancelled must report its cancel through a channel to be released; ausethat stops without reporting is never released. Before,acquireandreleasewere never cancelled andusewas released when its canceller returned. - Breaking: removed
onReleasePanic,onReleaseCrashandonReleaseThenfromCont.bracket: the outcome ofreleaseis part of the outcome ofbracket.
3.0.0 #
- Breaking:
OkPolicy.sequence/OkPolicy.quitFastnow returnOkPolicy<Never>, andCrashPolicy.sequence/CrashPolicy.quitFastreturnCrashPolicy<Never, Never>. They no longer take type arguments: remove them, e.g.OkPolicy.quitFast<String>()becomesOkPolicy.quitFast(). Combinators now infer their error and value types from their continuations instead ofdynamic. - Breaking: removed
absurdify,thenAbsurdifyandelseAbsurdifyfromContandContObserver. ANever-typedContcan be used directly where a wider type is expected.thenAbsurdandelseAbsurdremain. - Breaking: removed
ContRuntime.Cont.fromRun,runWithanddecoratereceive the environmentEdirectly:Cont.fromRun((env, observer) { ... }),runWith(env, observer)anddecorate((run, env, observer) { ... }). - Breaking: cancellation works through cancellers instead of polling
ContRuntime.isCancelled. The run function ofCont.fromRunreturns avoid Function()canceller (() {}for a computation that cannot be cancelled),runWithreturns the canceller of the computation it starts, and thedecoratecallback returns one.runstill returns aContCancelToken:cancel()now runs the cancellers, andisCancelled()only tells thatcancel()was called. Operators only forward a cancel to the parts that are running and to the parts that start afterwards; eachfromRunleaf decides what cancelling means and reports it through the existing channels, so a cancelled computation no longer stops silently. - Breaking:
quitFastcombinators (both,either,all,any,coalesce,convergeand their instance forms) cancel the inputs still running through their cancellers once the result is decided. - Breaking:
Cont.bracketforwards a cancel touseonly and runsreleaseonceusereports back, on any channel;acquireandreleaseare never cancelled. A cancel no longer releases the resource on its own. - Breaking: every sum type follows one convention: a sealed base, public case classes with private constructors, created through static methods on the base, and read with
switch.CrashOr.matchis removed. Its cases are now public,ValueCrashOrandCrashCrashOr; read them withswitch.MergedCrashandCollectedCrashhave no public constructors; useContCrash.mergeandContCrash.collect.- The policy case classes (
SequenceOkPolicy,QuitFastCrashPolicy, …) have no public constructors; useOkPolicy.sequence(),CrashPolicy.quitFast()and the other factories. toString()of these types uses the constructor style, e.g.NormalCrash(error, stackTrace),MergedCrash(left, right),ValueCrashOr(value).
- Breaking: removed
thenForever,elseForeverandcrashForever. Since a cancel now ends a loop, they could end on their own channel, which theirNevertypes ruled out. Use a predicate that is always true instead:thenWhile((_) => true),elseWhile((_) => true),crashWhile((_) => true). - Breaking: when a
Cont.fromRunleaf reports while its run function is still running, the next stage now starts after the run function returns, so code after the report runs first. Before, the next stage ran inside the report call. Leaves that report as their last instruction, as documented, behave the same. - The derived operators (taps, zips, forks, conditions, channel switches, loops,
*0/*WithEnvvariants,withEnvandlocal0),Cont.bracketandCont.fromDeferredare part of jerelo. - Added
thenUnitandelseUnit, which replace the value or the error with(). - Fixed
Contused through a wider error or value type (an upcast or aNever-typedCont) crashing with aTypeErrorat run time.runWithis now an extension method (ContRunWithExtension). - Fixed
CollectedCrashequality:==andhashCodenow compare the collected crashes by value instead of by map identity. - Fixed
MergedCrash.hashCodeignoring the order ofleftandright. - Fixed
CrashOrequality being asymmetric across type arguments, and its hash not telling a value from a crash. - Fixed
all,anyandconvergewith arunAllpolicy reporting a throwingcombineinconsistently: depending on which input finished last, the throw became a crash of one input in aCollectedCrash, a plain crash, or was ignored and its input's outcome dropped. A throwingcombineis now always a crash of the combinator: once every input has finished, the result is thatNormalCrash, as withboth,eitherandcoalesce. - Fixed long chains of synchronous steps overflowing the stack and losing their outcome (from about 400 steps).
thenDo,elseDo,crashDo,Cont.fromDeferred,localand everything built on them now run in a loop with constant stack space, so chains built in a loop, withfoldor by recursion can have any number of steps. Long chains also run several times faster. - Fixed
bothandeitherwith arunAllpolicy reporting an input that throws while starting at once, skipping the policy. Such a throw is now that input's crash: the combinator waits for the other input, followsshouldFavorCrash, and merges two crashes into aMergedCrash, asallandcoalescealready did. - Fixed
allandanywith aquitFastpolicy returning a fixed-length list, on whichaddthrew. They now return a growable list, like the other policies. - Fixed
ContCrash.collectkeeping the caller's map: changing it afterwards changed the crash, including its==andhashCode. ACollectedCrashnow keeps its own copy, andcrashesis unmodifiable. - Fixed
quitFastcombinators starting the remaining inputs after an earlier input had already decided the result synchronously; those inputs ran their start code, such as sending a request, only to be cancelled at once. Inputs are no longer started once the result is decided. - Fixed a throwing
onPaniclosing the panic it was handling: the zone receivedonPanic's own error. The original panic is now rethrown in a microtask. - Fixed
Cont.bracketsending a throwingonReleasePanicto the main computation'sonPanic, losing the release error. The release error is now rethrown in a microtask, as with a throwingonPanic. - Fixed a retry loop freezing inside
cancel(). When an attempt reported the cancel throughonElse, as the docs recommend,elseWhiletreated it as one more failure and started another attempt, which was cancelled at once and reported again; with an always-true predicate this never ended. After a cancel, loops (thenWhile,elseWhile,crashWhileand theuntilforms) now start no new iteration: they end with the outcome of the iteration that was running, without calling the predicate. - Fixed a throw after a computation already reported its outcome being silently dropped. In the run function of
Cont.fromRun, and inthenDo,elseDo,crashDoandCont.bracket, such a throw now goes toonPanic, and the outcome already reported stands; a throw before the outcome is still a crash. This matches the canceller, which already worked this way. - Documentation: stated that a throwing predicate or
fincrashUnlessThen,crashUnlessElse,crashRecoverThenandcrashRecoverElsecrashes with that exception instead of the original crash; that a crashing side effect or a throwingfinelseTapcrashes the computation; and that throwing after callingruninsidedecorateleaves the computation running and no longer cancellable. - Documentation: documented cancellation (
ContCancelToken, cancellers returned byfromRun, writing cancellable leaves, how operators,quitFastcombinators,Cont.bracketand forks handle a cancel); documentedthenUnitandelseUnit; rewrote the guide examples with core operators, including aretryhelper built onelseWhile; fixed stale names in doc comments, environment injection examples and theretryWithBackoffguide helper; removed theabsurdifyfamily; described combinator policies by their own channel and exits (includingCrashPolicy.quitFast,shouldFavorCrash, empty lists andrunAllcompletion order), crash types, observer guarantees, theonPanicdefault andfromRuncatching; added a note against upcasting the environment type.
2.0.0 #
- Split previous Else channel into Crash and Else channels
- Added new operators for Else and Crash channels
- Renamed
decorintodecorate - Replaced
elseIfwithelseUnless - Reworked combination operators and their policies
- Renamed
recoverandabortoperators todemoteandpromote - Removed
trapas it was not core operator, but rather an extension - Replaced
askThen's logic withask's one. - Added
askElseoperator - Renamed
injectIntointothenInject - Added
elseInjectoperator - Renamed
injectedByintoinjectedByThen - Added
injectedByElseoperator - Renamed
scopeintowithEnv - Bug fixes, improvements, performance improvements
1.0.3 #
- Fixed
trapfunction interface. - Decreased min dart version requirement.
1.0.2 #
- Reduced published package size (excluded
test/and extra documentation from release bundle).
1.0.1 #
- Renamed
foreverintothenForever - Added
elseForevermethod - Added
Cont.askThenstatic method - Added example