Is using async componentDidMount() good?

Is using componentDidMount() as an async function good practice in React Native or should I avoid it? I need to get some info from AsyncStorage when the component mounts, but the only way I know to make that possible is to make the componentDidMount() function async. async componentDidMount() { let auth = await this.getAuth(); if … Read more

Why does .json() return a promise?

I’ve been messing around with the fetch() api recently, and noticed something which was a bit quirky. let url = “http://jsonplaceholder.typicode.com/posts/6”; let iterator = fetch(url); iterator .then(response => { return { data: response.json(), status: response.status } }) .then(post => document.write(post.data)); ; post.data returns a Promise object. http://jsbin.com/wofulo/2/edit?js,output However if it is written as: let url … Read more

Wait until swift for loop with asynchronous network requests finishes executing

I would like a for in loop to send off a bunch of network requests to firebase, then pass the data to a new view controller once the the method finishes executing. Here is my code: var datesArray = [String: AnyObject]() for key in locationsArray { let ref = Firebase(url: “http://myfirebase.com/” + “\(key.0)”) ref.observeSingleEventOfType(.Value, withBlock: … Read more

C# 5 async CTP: why is internal “state” set to 0 in generated code before EndAwait call?

Yesterday I was giving a talk about the new C# “async” feature, in particular delving into what the generated code looked like, and the GetAwaiter() / BeginAwait() / EndAwait() calls. We looked in some detail at the state machine generated by the C# compiler, and there were two aspects we couldn’t understand: Why the generated … Read more

Asynchronous method call in Python?

I was wondering if there’s any library for asynchronous method calls in Python. It would be great if you could do something like @async def longComputation(): <code> token = longComputation() token.registerCallback(callback_function) # alternative, polling while not token.finished(): doSomethingElse() if token.finished(): result = token.result() Or to call a non-async routine asynchronously def longComputation() <code> token = … Read more

What is the difference between synchronous and asynchronous programming (in node.js)

I’ve been reading nodebeginner And I came across the following two pieces of code. The first one: var result = database.query(“SELECT * FROM hugetable”); console.log(“Hello World”); The second one: database.query(“SELECT * FROM hugetable”, function(rows) { var result = rows; }); console.log(“Hello World”); I get what they’re supposed to do, they query the database to retrieve … Read more