Skip to content

Instantly share code, notes, and snippets.

@TheAnimatrix
Last active September 15, 2019 14:39
Show Gist options
  • Save TheAnimatrix/5334e170b04dab02b939857f9fe3eea0 to your computer and use it in GitHub Desktop.
Save TheAnimatrix/5334e170b04dab02b939857f9fe3eea0 to your computer and use it in GitHub Desktop.
doubt
import 'package:http/http.dart' as http;
void main() async{
int i = 1;
bool run = true;
var url = 'http://example.com/whatsit/create';
var future =
http.post(url, body: {'name': 'doodle', 'color': 'blue'});
future.then((response){
print('Response status: ${response.statusCode}');
print('Response body: ${response.body}');
});
while(true){ //why isn't the loop blocked by the http request ? how does it complete while the loop is executing ?
print(i++);
await sleep(); //this is required to return control to the event queue ? why ? why does it take adding a task to the queue to process the task prior to it ? isn't it FIFO based ?
}
}
Future sleep() {
return new Future.delayed(const Duration(milliseconds: 1), () => "1");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment