Update and get
See original GitHub issueI want there to be a method on a Var[A]
that takes in a function A -> (A,B)
and returns a B
. This would be a generalization of update
. This can be simulated using now()
and set()
, but then there are two separate transactions.
Also, is there a way of doing this without modifying Airstream itself that I am missing?
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Eloquent update and get record back - Stack Overflow
Is there a more efficient way to update and get the records in one call/request to the database? php · mysql · laravel...
Read more >Check & update your Android version - Google Help
Get the latest Android updates available for you · Open your phone's Settings app. · Near the bottom, tap System and then System...
Read more >get update or get updates? - TextRanch
Here's how to get updates for Windows and other Microsoft programs at the same time, including updates for Microsoft Office (Word, Outlook ,...
Read more >Get the latest Windows update - Microsoft Support
To check for updates, select Start > Settings > Windows Update , then select Check for updates. If updates are available, you can...
Read more >sudo apt-get update vs upgrade – What is the Difference?
sudo apt-get update and sudo apt-get upgrade are two commands you can use to keep all of your packages up to date in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
OK, this is actually fine though, because I could actually wrap this in a future and then pass
b
into the callback. This is already inside of some async stuff, so this meshes well. I think you can close this issue now. Thank you so much for helping me out here!@olynch Although Javascript itself is single threaded, because of Airstream’s transaction system, the
$a.set
method is not guaranteed to actually update the Var immediately, it can de delayed until the current transaction is done. See https://github.com/raquo/Airstream#var-transaction-delay for details.So yes, if you just write that snippet of yours, your other code can indeed change the value of
$a
after you called$a.now()
, but before you called$a.set
, for example if you have the following all inside the same Observer callback:As I mentioned, to solve this, you need to wrap the code that you want to run together/unbroken in a new Transaction. There are several ways to do it, but I guess the most obvious is this:
For this to work, any
$a.set
/$.update
that you do before$a.now()
must be outside ofnew Transaction
, if you want$a.now()
to see those updates.Notice that you can’t return
B
from thenew Transaction
block, for similar reasons why you can’t returnB
from an expression that isFuture[B]
– theB
is not available yet.We could potentially make Transactions return a value and provide a Future-like API with
onComplete
to get the value when it’s ready, but there would need to be some real strong justification for that.