Skip to content

Commit

Permalink
Merge pull request #208 from near/serhii/promise-result
Browse files Browse the repository at this point in the history
prommiseResult throws an error
  • Loading branch information
volovyks authored Sep 9, 2022
2 parents ef90663 + d1dd612 commit 481bbd6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions lib/api.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions lib/api.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,19 +341,15 @@ export function promiseResultsCount(): bigint {
return env.promise_results_count();
}

export function promiseResult(
resultIdx: number | bigint
): Bytes | PromiseResult.NotReady | PromiseResult.Failed {
export function promiseResult(resultIdx: number | bigint): Bytes {
let status: PromiseResult = env.promise_result(resultIdx, 0);
if (status == PromiseResult.Successful) {
return env.read_register(0);
} else if (
status == PromiseResult.Failed ||
status == PromiseResult.NotReady
) {
return status;
} else {
throw Error(`Unexpected return code: ${status}`);
throw Error(
`Promise result ${status == PromiseResult.Failed ? "Failed" :
status == PromiseResult.NotReady ? "NotReady" : status}`
);
}
}

Expand Down

0 comments on commit 481bbd6

Please sign in to comment.