buzz icon indicating copy to clipboard operation
buzz copied to clipboard

Allow per resume/resolve error handling

Open giann opened this issue 3 years ago • 0 comments

Right now if a fiber fails, we can only handle errors at the fiber creation site. Allow to handle error on any resume or resolve:

fun count(num n) > str > num? {
    for (num i = 0; i < n; i = i + 1) {
    	if (i == 2) {
	    throw "an error occured";
	}
        yield i;
    }

    return "Counting is done!";
}

fun main() > void {
    fib<str, num?> counter = &count(10);
    
    num sum = 0;
    while (!counter.over()) {
        sum = sum + (resume counter catch 0) ?? 0;
    }

    print(resolve counter catch "Ooops);
}

A fiber that failed on a resume is over. A subsequent resume or resolve should raise an error.

giann avatar Aug 09 '22 13:08 giann