async-await

ReactJS setState when all nested Axios calls are finished

我的梦境 提交于 2020-05-14 12:16:04
问题 I have a problem with updating my state from nested axios call inside forEach loop: constructor(props) { super(props); this.state = { isLoaded: false, items: [] }; //Binding fetch function to component's this this.fetchFiles = this.fetchFiles.bind(this); } componentDidMount() { this.fetchFiles(); } fetchFiles() { axios.get('/list') .then((response) => { var items = response.data.entries; items.forEach((item, index) => { axios.get('/download'+ item.path_lower) .then((response) => { item.link =

Is it possible to wait for Device.BeginInvokeOnMainThread code to finish (continue background work with results of a UI call)

∥☆過路亽.° 提交于 2020-05-14 04:06:07
问题 In my code I have a task called "ShowMessageBoxAsync". I want to use this code to show (and await) the DisplayAlert to the user and return the result. Like this: var messageBoxResult = await View.ShowMessageBoxAsync("This is an error"); The code for the ShowMessageBoxAsync is: public async System.Threading.Tasks.Task<bool> ShowMessageBoxAsync(string message) { var result = false; Device.BeginInvokeOnMainThread(async () => { result = await DisplayAlert("Error", message, "OK", "Cancel"); });

Is it possible to wait for Device.BeginInvokeOnMainThread code to finish (continue background work with results of a UI call)

时光怂恿深爱的人放手 提交于 2020-05-14 04:02:23
问题 In my code I have a task called "ShowMessageBoxAsync". I want to use this code to show (and await) the DisplayAlert to the user and return the result. Like this: var messageBoxResult = await View.ShowMessageBoxAsync("This is an error"); The code for the ShowMessageBoxAsync is: public async System.Threading.Tasks.Task<bool> ShowMessageBoxAsync(string message) { var result = false; Device.BeginInvokeOnMainThread(async () => { result = await DisplayAlert("Error", message, "OK", "Cancel"); });

how to mock AWS library in jest

孤街浪徒 提交于 2020-05-13 11:06:06
问题 I am using signIn method from 'aws-amplify' library. I am not able to call signIn method from this library while running test case in jest. Code: import { Auth } from "aws-amplify"; // import statement //code for function handleSubmit = async event => { event.preventDefault(); this.setState({ isLoading: true }); try { await Auth.signIn(this.state.username, this.state.password); this.props.history.push("/dashboard"); } catch (e) { this.setState({ isLoading: false }); } } Test file: it('calls

how to mock AWS library in jest

*爱你&永不变心* 提交于 2020-05-13 11:05:06
问题 I am using signIn method from 'aws-amplify' library. I am not able to call signIn method from this library while running test case in jest. Code: import { Auth } from "aws-amplify"; // import statement //code for function handleSubmit = async event => { event.preventDefault(); this.setState({ isLoading: true }); try { await Auth.signIn(this.state.username, this.state.password); this.props.history.push("/dashboard"); } catch (e) { this.setState({ isLoading: false }); } } Test file: it('calls

Difference between returning new Promise and Promise.resolve

故事扮演 提交于 2020-05-11 06:28:40
问题 For the below code snippet, i would like to understand how NodeJS runtime handles things : const billion = 1000000000; function longRunningTask(){ let i = 0; while (i <= billion) i++; console.log(`Billion loops done.`); } function longRunningTaskProm(){ return new Promise((resolve, reject) => { let i = 0; while (i <= billion) i++; resolve(`Billion loops done : with promise.`); }); } function longRunningTaskPromResolve(){ return Promise.resolve().then(v => { let i = 0; while (i <= billion) i++

Dealing with throttling/rate limits (429 error) when using async/await

浪子不回头ぞ 提交于 2020-05-11 02:55:29
问题 I have the following async code that gets called from so many places in my project: public async Task<HttpResponseMessage> MakeRequestAsync(HttpRequestMessage request) { var client = new HttpClient(); return await client.SendAsync(request).ConfigureAwait(false); } An example of how the above method gets called: var tasks = items.Select(async i => { var response = await MakeRequestAsync(i.Url); //do something with response }); The ZenDesk API that I'm hitting allows about 200 requests per

Dealing with throttling/rate limits (429 error) when using async/await

孤街醉人 提交于 2020-05-11 02:55:17
问题 I have the following async code that gets called from so many places in my project: public async Task<HttpResponseMessage> MakeRequestAsync(HttpRequestMessage request) { var client = new HttpClient(); return await client.SendAsync(request).ConfigureAwait(false); } An example of how the above method gets called: var tasks = items.Select(async i => { var response = await MakeRequestAsync(i.Url); //do something with response }); The ZenDesk API that I'm hitting allows about 200 requests per

Dealing with throttling/rate limits (429 error) when using async/await

人盡茶涼 提交于 2020-05-11 02:55:09
问题 I have the following async code that gets called from so many places in my project: public async Task<HttpResponseMessage> MakeRequestAsync(HttpRequestMessage request) { var client = new HttpClient(); return await client.SendAsync(request).ConfigureAwait(false); } An example of how the above method gets called: var tasks = items.Select(async i => { var response = await MakeRequestAsync(i.Url); //do something with response }); The ZenDesk API that I'm hitting allows about 200 requests per

Async/await axios calls with Vue.js

旧城冷巷雨未停 提交于 2020-05-10 04:17:38
问题 I'm having a little trouble setting one of my this. values within my Vue.js application. I believe I'm either not understanding async axios calls correctly, or how async works within Vue.js. I have the following three methods: updateAvailability(availability) { if (availability == true) { this.showYourDetails(); } else { this.showBookingDetails(); } }, checkAvailability: async function(event) { event.preventDefault(); const availability = await this.handleAvailabilityRequest(event); this