Async Await Angular 14 - asynchronous

I get a notification that ToPromise has been deprecated and the only examples I can see about doing async await in Angular show using ToPromise.
What is the "new" way to do this?
Thanks in advance.

Related

.once() doesn't seem to work / recognized while working with Flutter & Firebase

I am trying to fetch some data from FireStore and store it in a local list to be displayed later in the form of cards. I have seen many tutorials where people have used .once() to fetch data.
Now, when I am trying to do the same then getting error like the word isn't recognized.
#override
void initState() {
super.initState();
CollectionReference dbRefItem = FirebaseFirestore.instance.collection("items");
***dbRefItem.once().then***
}
I cant seem to find any documentation if it has been deprecated or am I doing something wrong! Hovering cursor on the error says
"The method 'once' isn't defined for the type 'CollectionReference'.
Try correcting the name to the name of an existing method, or defining
a method named 'once'."
.get() did the same job as .once()
However, .once() syntax is not being accepted by Flutter's latest SDK while worked on the previous one. Have raised a ticket with Flutter Dev forum.

how to obtain a particular document from a collection in firestore using Flutter

I am new to dart and so obviously to flutter... I did integrate firestore and did programming in android java.. and so I am finding it a little bit difficult to understand what means what in android java and flutter in regards to Firestore.
e.g. whats the alternative to addOnCompleteListener(android java) in flutter?
Regarding your question about how to get the document from collection you can refer the following code
DocumentReference documentReference =
Firestore.instance.collection("users").document("John");
documentReference.get().then((datasnapshot) {
if (datasnapshot.exists) {
print(datasnapshot.data['email'].toString(););
}
else{
print("No such user");
}
consider users collection has a document named as John with data as email: "j#gmail.com".
You can find the documentation very useful and almost all the functions are present for the flutter too. Just you should be able to do error and exception handling.
oncomplete() and listen() functions might be very helpful.
Hope it helped.

Wrap async usage with Meteor

I'm trying to wrap an async function inside my Meteor app.
To make it maximum simple I will try to make a basic example (because all I found was kinda more complex that i actly need).
In my app I am trying to do
console.log("1");
my_func(string_to_display);
console.log("2");
As node is async I get logs 1 and 2 before to see the string i sent to the function.
I tried to call it this way
var my_func_sync = Meteor.wrapAsync(my_fync);
var result = my_func_sync(string_to_display);
Most examples here are more complex, with URLs and calls between server/client/other services. I would like to know if there is a way to wrap a simple function that will only send my string to console. Could anyone give me a most basic example ever please? Would be highly appreciated!
I guess using async await can sort the issue.
async my_funct1(){
console.log("1");
await my_func(string_to_display);
console.log("2");
}
Note that you will need to use async with my_funct1() if you need to use await. This will typically wait for the call to return back from myfunc(string_to_display) to proceed to the next line.

Can I use async and await with Tornado-redis? (Python 3.5)

Tornado 4.3 has added support for PEP 0492 which introduces async and await keywords for defining and calling asynchronous coroutines. Is it possible to use these keywords to call tornado-redis API's instead of "yield tornado.gen.Task"?
Thank You!
You can use await tornado.gen.Task. await is a direct replacement for yield, but doesn't affect whether gen.Task is necessary.
Have not tried it, but yes theoretically you can.
Also, if you'll be making use of asyncio, you can bridge the two.

Using .numChildren() in AngularFire

I'm trying to use .numChildren() in AngularFire, but not sure I'm doing it correctly.
function getServiceProviders(serviceId) {
var serviceProviders = ref.child('services').child(serviceId).child('providers');
return serviceProviders.numChildren();
}
I'm getting the following error:
TypeError: e.numChildren is not a function
Not sure if this is due to me using Browserify, or I'm just trying to access numChildren incorrectly.
Any help is appreciated. Thanks in advance!
Your code snippet doesn't use AngularFire, it only uses the Firebase JavaScript SDK. Although your project undoubtedly uses AngularFire, it doesn't relate to this question.
When you look at the documentation for the .child() method in the Firebase JavaScript SDK, you'll see that it returns a Firebase reference. And if you look further into that class, you should notice that it doesn't have a numChildren method.
numChildren is only available on a DataSnapshot object, which you get in any of the on(... event handlers.
So:
serviceProviders.on('value', function(snapshot) {
console.log(snapshot.numChildren());
}
Since the snapshot will be loaded asynchronously, you cannot return the number of children from getServiceProviders. See my answer to this question for a broader explanation of that: Asynchronous access to an array in Firebase

Resources