This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
// Prints: "1", "4", "2", and "3". | |
main() { | |
print('1'); | |
getInFuture2().then(print); | |
getInFuture3().then(print); | |
print('4'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
main() { | |
final completer = new Completer<String>(); | |
completer.future.then(print); | |
completer.complete('Hello World'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:isolate'; | |
/// Prints "6765" and again "6765". | |
main() async { | |
// Compute and print a fibonacci sequence synchronously. | |
print(syncFibonacci(20)); | |
// Compute and print a fiboacci sequence on another thread (isolate). | |
print(await asyncFibonacci(20)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:convert'; | |
import 'dart:io'; | |
import 'dart:isolate'; | |
/// Prints {name: Joe User}, {name: Joe User}, and {name: Joe User}. | |
main() async { | |
// Reads and decodes a file synchronously. | |
print(readSync()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'dart:convert'; | |
import 'dart:io'; | |
main() async { | |
final feed1 = getFeedSize(); | |
if (feed1 is Future) { | |
print('From RPC: ${await feed1} bytes.'); | |
} | |
final feed2 = getFeedSize(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// The 'Router' itself is just a stream of changes. | |
abstract class Router implements Stream<RouteChange> {} | |
/// An example of a route. | |
class Route { | |
final String path; | |
final Map<String, String> queryParameters; | |
const Route(this.path, {this.queryParameters: const {}}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
main() { | |
final router = new Router(); | |
router.listen(print); | |
router.route(const Route('/', query: const {'referredId': '1234'})); | |
router.route(const Route('/contact')); | |
} | |
/// A simple example of a 'Router' that is just a stream of [Route]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
main() { | |
final router = new Router(); | |
router.listen(print); | |
router.route(const Route('/', query: const {'referredId': '1234'})); | |
router.route(const Route('/contact')); | |
} | |
/// A simple example of a 'Router' that is just a stream of [Route]. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
main() async { | |
final router1 = new Router(); | |
print('--- Router 1 ---'); | |
router1.listen(print); | |
router1.route(const Route('/', query: const {'referredId': '1234'})); | |
router1.route(const Route('/contact')); | |
await new Future((){}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Animal { | |
void consume(Food food) { | |
System.out.println("Ate " + food.weight + " pounds of food!"); | |
} | |
void consume(Water water) { | |
System.out.println("Drank " + water.amount + " liters of water!"); | |
} | |
static void main(String[] args) { |