Skip to content

Commit 891bd9d

Browse files
committed
Add .get{Option,OrThrow} to SetOnceVar
japgolly/webapp-util#29
1 parent 8d8916d commit 891bd9d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

utils/shared/src/main/scala/japgolly/microlibs/utils/SetOnceVar.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@ final class SetOnceVar[A] {
1313
a
1414
}
1515
}
16+
17+
def getOption(): Option[A] =
18+
synchronized(instance)
19+
20+
def getOrThrow(): A =
21+
getOrThrow("SetOnceVar not yet set.")
22+
23+
def getOrThrow(errMsg: => String): A =
24+
getOption().getOrElse(throw new RuntimeException(errMsg))
1625
}
1726

1827
object SetOnceVar {
1928
def apply[A]: SetOnceVar[A] =
2029
new SetOnceVar
21-
}
30+
}

0 commit comments

Comments
 (0)