-
Notifications
You must be signed in to change notification settings - Fork 80
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
Events for simple coffee machine #1229
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1229 +/- ##
=======================================
Coverage 77.77% 77.77%
=======================================
Files 84 84
Lines 17476 17476
Branches 1770 1770
=======================================
Hits 13592 13592
Misses 3848 3848
Partials 36 36 ☔ View full report in Codecov by Sentry. |
That would mean that when
How does the code prevent that this is not happening? |
Just to be precise, it is the emitEvent that is the issue. I am only sending a GET request from the browser to localhost:8081/coffee-machine/events/resourceEmpty and if both conditions are met, I get |
I had to adapt the code a bit, a bit more than just adding an event. Now there are arrays for refilling and empty event so that there can be more resources empty etc. This avoid the race condition but also makes it more logical (both resources can finish at the same time and you want to fill both at the same time) |
if (resourceEvent.length > 0) { | ||
thing.emitEvent("resourceEmpty", resourceEvent); | ||
return undefined; | ||
} else { | ||
return undefined; | ||
} |
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.
I think now we can have just once
return undefined;
if (resourceEvent.length > 0) { | ||
thing.emitEvent("resourceEmpty", resourceEvent); | ||
return undefined; | ||
} else { | ||
return undefined; | ||
} |
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.
Same here
if (resourceEvent.length > 0) { | ||
thing.emitEvent("resourceEmpty", resourceEvent); | ||
return undefined; | ||
} else { | ||
return undefined; | ||
} |
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.
And here also, just one return statement
@danielpeintner adapted to your feedback |
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.
Since we are using the value function is better to cast than to ignore ts error. I fixed it and I think we can now merge.
CI still randomly falling, merging anyway. |
This is adding events to the simple coffee machine. With @relu91 we will use this in the nodejs conf presentation. There are those return statements added after event emissions since without doing that I was getting an event emission with data
"water""beans"
. Some race condition maybe? It is not an elegant solution but if that is indeed an issue with node-wot (and not my oversight), I would propose to go with this PR and open an issue about it.