From 0d03fafbfec4545098023b7147c5f8fb6ae06f99 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 5 Sep 2018 22:13:36 -0400 Subject: Map promises onto futures. Refactors handlers.rs The idea is that all Deno "ops" (aka bindings) should map onto a Rust Future. By setting the "sync" flag in the Base message users can determine if the future is executed immediately or put on the event loop. In the case of async futures, a promise is automatically created. Errors are automatically forwarded and raised. TODO: - The file system ops in src/handler.rs are not using the thread pool yet. This will be done in the future using tokio_threadpool::blocking. That is, if you try to call them asynchronously, you will get a promise and it will act asynchronous, but currently it will be blocking. - Handlers in src/handler.rs returned boxed futures. This was to make it easy while developing. We should try to remove this allocation. --- js/errors.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'js/errors.ts') diff --git a/js/errors.ts b/js/errors.ts index 11d4cd509..2d0572e6d 100644 --- a/js/errors.ts +++ b/js/errors.ts @@ -10,8 +10,17 @@ export class DenoError extends Error { // @internal export function maybeThrowError(base: fbs.Base): void { + const err = maybeError(base); + if (err != null) { + throw err; + } +} + +export function maybeError(base: fbs.Base): null | DenoError { const kind = base.errorKind(); - if (kind !== fbs.ErrorKind.NoError) { - throw new DenoError(kind, base.error()!); + if (kind === fbs.ErrorKind.NoError) { + return null; + } else { + return new DenoError(kind, base.error()!); } } -- cgit v1.2.3