Skip to content

Commit

Permalink
👍Clarify halt() error behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboyd committed Aug 7, 2023
1 parent 619f9ee commit 834e9c7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions www/docs/errors.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,35 @@ nor will it ever raise an error. And, because it will produce neither
a positive nor negative outcome, it is an error to `await` the result
of a halted operation.

When this happens, the promise is rejected with a special halt error:
When this happens, the promise is rejected with a special halt error.
In this example, we show a very long running task that is stopped in the
middle of its work even though it would eventually return a value if we
waited long enough.

``` typescript
import { run, suspend } from 'effection';
import { run, sleep } from 'effection';

async function runExample() {
// this task takes a long time to return
let task = run(function*() {
yield* sleep(10_000_000);
return "hello world";
});

try {
let task = run(supsend);
// halt it. It will no longer result in "hello world"
await task.halt();

// no value will ever be available no matter how long we `await`.
await task;
} catch(err) {
console.log("got error", err.message) // => "got error halted"
console.log(err.message) // => "halted"
}
}
```

Notice how it is not an error to `await` the halt operation itself, only to
`await` the outcome of a halted operation.
Notice how it is not an error to await the `task.halt()` operation, only
to `await` the outcome of the operation which has been halted.

## Error propagation

Expand Down

0 comments on commit 834e9c7

Please sign in to comment.