mirror of
https://github.com/logos-storage/questionable.git
synced 2026-01-10 01:33:06 +00:00
fix error binding in without statement on multiple threads
This commit is contained in:
parent
e56cf86c4a
commit
5c8d422ac8
@ -1,7 +1,7 @@
|
|||||||
import std/options
|
import std/options
|
||||||
|
|
||||||
var captures {.global, compileTime.}: int
|
var captures {.global, compileTime.}: int
|
||||||
var errorVariable: ptr ref CatchableError
|
var errorVariable {.threadvar.}: ptr ref CatchableError
|
||||||
|
|
||||||
template captureBindError*(error: var ref CatchableError, expression): auto =
|
template captureBindError*(error: var ref CatchableError, expression): auto =
|
||||||
let previousErrorVariable = errorVariable
|
let previousErrorVariable = errorVariable
|
||||||
|
|||||||
@ -3,8 +3,11 @@ import std/options
|
|||||||
import std/sequtils
|
import std/sequtils
|
||||||
import std/strutils
|
import std/strutils
|
||||||
import std/sugar
|
import std/sugar
|
||||||
|
import std/threadpool
|
||||||
import pkg/questionable/results
|
import pkg/questionable/results
|
||||||
|
|
||||||
|
{.experimental: "parallel".}
|
||||||
|
|
||||||
suite "result":
|
suite "result":
|
||||||
|
|
||||||
let error = newException(CatchableError, "error")
|
let error = newException(CatchableError, "error")
|
||||||
@ -401,6 +404,14 @@ suite "result":
|
|||||||
|
|
||||||
foo()
|
foo()
|
||||||
|
|
||||||
|
test "without statement with error works with multiple threads":
|
||||||
|
proc fail(number: int) =
|
||||||
|
without _ =? int.failure "error" & $number, error:
|
||||||
|
check error.msg == "error" & $number
|
||||||
|
parallel:
|
||||||
|
for i in 0..<1000:
|
||||||
|
spawn fail(i)
|
||||||
|
|
||||||
test "catch can be used to convert exceptions to results":
|
test "catch can be used to convert exceptions to results":
|
||||||
check parseInt("42").catch == 42.success
|
check parseInt("42").catch == 42.success
|
||||||
check parseInt("foo").catch.error of ValueError
|
check parseInt("foo").catch.error of ValueError
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user