Comments (8)
So it looks like until()
decrements the cv even when it hits the timeout. So I can create an even smaller reprex:
library(nanonext)
#> Warning: package 'nanonext' was built under R version 4.3.1
cv <- cv()
cv_value(cv)
#> [1] 0
cv_signal(cv)
cv_signal(cv)
cv_value(cv)
#> [1] 2
until(cv, 10) # decrements the cv
cv_value(cv)
#> [1] 1
Created on 2023-10-03 with reprex v2.0.2
@shikokuchuo, is the decrement always guaranteed to happen on every call to until()
. If so, I might be able to work with this by defining my own version:
crew_until <- function(condition, seconds_timeout) {
on.exit(nanonext::cv_signal(condition))
nanonext::until(cv = condition, msec = 1000 * seconds_timeout)
}
I will test this.
from nanonext.
Hmm..., it looks like nanonext::until()
cannot decrement the cv any further if it is already 0, so then cv_signal(condition)
would be incorrect. And writing if (cv_value(condition) > 0L) cv_signal(condition)
is a race condition because what if a task completes after if()
but before cv_signal()
?
On my end, the only other solution I can think of is to preemptively call cv_signal()
a few thousand times before I submit any tasks at all, but that seems really messy, and I am not sure what edge cases that would cause.
So then would it be possible for until()
to not signal the cv in the first place?
from nanonext.
Hmm... maybe I am misunderstanding the intended use cases of wait()
and until()
. I can see now that this is the intended behavior in the docs. In addition, I notice that until()
only waits if cv_value(cv)
is 0. Any positive value will not cause a wait:
library(nanonext)
cv <- cv()
cv_signal(cv)
until(cv, 10000) # returns control instantly
This creates a challenge for me when using mirai::nextget("cv")
. I would like to be able to wait on different kinds of conditions. Mainly:
- Wait until a
cv
value changes, regardless of its current value, without changing its value further. - Wait until
cv_value(cv)
reaches a certain fixed number.controller$wait()
andcontroller$map()
could be simplified a lot with something likenanonext::until(cv, msec, value_wake_up = 7L, decrement_value = FALSE)
.
from nanonext.
And I think a manual cv_decrement()
could also add a stronger meaning to nextget("cv")
. Currently, cv_value(nextget("cv"))
is the number of resolved tasks in the lifetime of the crew
controller, regardless of whether they have been returned with pop()
. If nanonext
were to support a manual way to decrement a cv, then I could decrement it on each controller$pop()
. Now, the cv
would indicate the number of resolved tasks currently available for collection, which is much more powerful and would allow me to make controller$wait()
simpler and more efficient.
from nanonext.
until(cv, 1)
decrements your cv safely.
from nanonext.
until()
is correct and behaves as documented. If it is something else you are after please open a new feature request. It will not be implemented as a change to until()
. Thanks.
from nanonext.
Sorry, that was a lot of thinking out loud on my part.
from nanonext.
No worries! My comment just meant that any new functionality should belong in a new function. These synchronisation primitives are basic building blocks and it would not be right to amend them however convenient it may seem.
from nanonext.
Related Issues (16)
- Installation issue on Raspberry Pi 4 HOT 8
- Release a version that uses dynamically linked NNG (which is also released) HOT 3
- Compilation issue on Ubuntu HOT 2
- not compiling on university cluster (no sudo access) HOT 4
- System endianness bug affecting nanonext 0.9.2 HOT 1
- Installation error "bad variable name" HOT 4
- Wait on multiple condition variables? HOT 9
- Condition variables to reduce polling in crew
- nanonext : which kind of protocol we must use for working with 'future' package ? HOT 4
- Forwarding to ephemeral condition variables HOT 15
- Performance of TLS encryption with a small number of small tasks HOT 6
- nanonext is mutating the `NA` value shared across all R packages HOT 3
- Building errors - [ Fedora using system libs ] HOT 7
- Compiler choice building bundled nng 1.6.0 HOT 15
- Patch for missing AI_NUMERICSERV: possible to add? HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanonext.