-
-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promise resolver and promise result #76
Conversation
Codecov Report
@@ Coverage Diff @@
## master #76 +/- ##
==========================================
+ Coverage 94.07% 94.64% +0.57%
==========================================
Files 10 11 +1
Lines 388 411 +23
==========================================
+ Hits 365 389 +24
+ Misses 16 15 -1
Partials 7 7
Continue to review full report at Codecov.
|
Dose
|
You should be able to reject with any "Value" which includes a string, but it's most common to use an Error/Exception |
Just a quick update: Sorry for taking so long in getting this PR finished; it's almost done. Annoyingly, I'm in the process of moving house, so packing boxes has been taking most of my spare time 😞 Should be fully moved in by this time next week, and should be able to continue my work on v8go. |
I'm not experienced with v8 but like to ask a question. for prom.State() == v8go.Pending {
continue
} It seems, this is constantly calling the cgo bridge, doesn't it? |
@jensneuse Thanks for the suggestion. Hopefully this helps answer your questions:
It does 😓
Not really. The main issues around performance arise from transferring large amounts of data between C and Go and having to copy that data into memory on the Go side to make sure it does not get freed on the C side before you use it on the Go side. This func is returning an enum aka integer by value so you shouldn't notice any overhead in doing this in Go over doing the same thing in C++.
It's a nice idea, but one of the goals of the project is stay as close to the V8 API as possible; it also has a lot larger overhead as callbacks are not an easy thing to manage between Go and C (Have a look at the FunctionTemplate code to get an idea of the complexity) |
I'm having a hard time with getting Error Exceptions working. This simple line is causing a segfault: Exception::Error(String::Empty(iso)); I've verified that the It's not critical for this PR to have the Exception/Error objects, but I thought it would be nice for the Promise rejections. I'm tempted to exclude the |
It seems like that can come in a follow-on commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, some small comments.
// The associated Promise will be in a Pending state. | ||
func NewPromiseResolver(ctx *Context) (*PromiseResolver, error) { | ||
if ctx == nil { | ||
return nil, errors.New("v8go: Context is required") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nite: lowercase?
Hi @rogchap It supports top level Could you please update the V8 binary file version? |
@kuoruan Top level await only works at the top level of a module not at the top top level; which is a bit miss leading. It's still behind a feature flag but I'll look to see if we can add it and upgrade v8 to the latest stable version. I'll do this in a seperate PR |
} | ||
|
||
// Reject | ||
func (r *PromiseResolver) Reject(err *Value) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not change this to Valuer?
So that we can reject an object here
for prom.State() == v8go.Pending { @rogchap Hi, I don't always wait for promise results, Are there more effective ways to resolve this problem? |
Enables the (basic) Promise API. eg:
resolves #69