This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored, added Finalizable and response events.
- Loading branch information
Showing
3 changed files
with
42 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package pro.savant.circumflex | ||
package core | ||
|
||
/*! `Finalizable` trait adds abstract finalization functionality | ||
based on collecting functions `() => Unit` in current context. | ||
The implementation then decides when to perform such finalization | ||
(i.e. execute all the functions). | ||
*/ | ||
trait Finalizable { | ||
|
||
protected def baseName = "finalizers" | ||
|
||
def finalizers = ctx.getAs[Seq[() => Unit]](baseName).getOrElse(Nil) | ||
|
||
def enqueueFinalizer(key: String, fn: () => Unit) { | ||
if (!ctx.contains(baseName + "." + key)) { | ||
ctx.update(baseName + "." + key, true) | ||
ctx.update(baseName, finalizers ++ Seq(fn)) | ||
} | ||
} | ||
|
||
def pushFinalizer(key: String, fn: () => Unit) { | ||
if (!ctx.contains(baseName + "." + key)) { | ||
ctx.update(baseName + "." + key, true) | ||
ctx.update(baseName, Seq(fn) ++ finalizers) | ||
} | ||
} | ||
|
||
def doFinalize() { | ||
finalizers.foreach(_.apply()) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters