Ejemplo n.º 1
0
            private DotNetValue OnCalled(IntPtr deferred)
            {
                try
                {
                    if (_task.IsCompleted)
                    {
                        var exception = UnwrapAggregateException(_task.Exception);
                        var value     = exception == null
                                        ? DotNetValue.FromObject(GetResult(_task), _parent)
                                        : DotNetValue.FromException(exception);

                        _parent.NativeMethods.CompletePromise(_parent._context, deferred, value);
                    }
                    else
                    {
                        _task.ContinueWith(t =>
                        {
                            var exception = UnwrapAggregateException(t.Exception);
                            var value     = exception == null
                                                               ? DotNetValue.FromObject(GetResult(t), _parent)
                                                               : DotNetValue.FromException(exception);
                            _parent.NativeMethods.CompletePromise(_parent._context, deferred, value);
                        },
                                           _parent._scheduler);
                    }

                    return(new DotNetValue {
                        Type = DotNetType.Null, Value = IntPtr.Zero, ReleaseFunc = null
                    });
                }
                catch (Exception e)
                {
                    return(DotNetValue.FromException(e));
                }
                finally
                {
                    _parent._taskRegistry.Remove(CallbackPtr);
                }
            }
Ejemplo n.º 2
0
            private void OnCalled(int argc, JsValue[] argv, out DotNetValue result)
            {
                System.Diagnostics.Debug.Assert(argc == (argv?.Length ?? 0), "Marshalling is broken");

                try
                {
                    result = (DotNetValue)_parent._scheduler.RunCallbackSynchronously(
                        state => Wrapped((JsValue[])state),
                        argv ?? new JsValue[0]);
                }
                catch (Exception exception)
                {
                    if (exception is AggregateException aggregateException)
                    {
                        exception = UnwrapAggregateException(aggregateException);
                    }
                    if (exception is TargetInvocationException targetInvocationexception)
                    {
                        exception = targetInvocationexception.InnerException;
                    }

                    result = DotNetValue.FromException(exception);
                }
            }