Skip to content

Commit 9db1616

Browse files
committed
feat(core): add protect
1 parent 9584dc6 commit 9db1616

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/RescriptCore.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@ type undefined<+'a> = Js.undefined<'a>
6868
type nullable<+'a> = Js.nullable<'a>
6969

7070
let panic = Core__Error.panic
71+
72+
let protect = (~finally, f) => {
73+
let result = try f() catch {
74+
| exn =>
75+
finally()
76+
raise(exn)
77+
}
78+
finally()
79+
result
80+
}

0 commit comments

Comments
 (0)