Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for await #47

Closed
FlowIT-JIT opened this issue Sep 10, 2018 · 2 comments
Closed

Support for await #47

FlowIT-JIT opened this issue Sep 10, 2018 · 2 comments
Labels

Comments

@FlowIT-JIT
Copy link
Collaborator

FlowIT-JIT commented Sep 10, 2018

Async. operations such as HTTP Requests should return a thenable or promise to support await and .then(..).

A good article on the subject can be found here:
https://developers.google.com/web/fundamentals/primers/promises

Quick and dirty example of the concept of thenables which would be cross browser compatible - the use of promises would not: https://caniuse.com/#feat=promises

async function getData()
{
	var callbacks = { resolve: undefined, reject: undefined };
	var promise = { then: function(resolve, reject) { callbacks.resolve = resolve; callbacks.reject = reject; } };

	setTimeout(function() { callbacks.resolve("Hello world"); }, 2000);
	
	return promise;
}

// Test using .then(..)
getData().then(function(res) { console.log("Thenable result: ", res); });

// Test using await
var result = await getData();
console.log("Awaited result: ", result);
@FlowIT-JIT
Copy link
Collaborator Author

Closed as this was obviously a bad idea since we cannot mark functions as async since IE does not support this. So functionality within Fit.UI should not be async and return promises by default.
However, having some sort of Promise/Thenable object that is compatible with the native implementation might make sense at some point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant