Skip to content

Instantly share code, notes, and snippets.

@dotdoom
Created March 15, 2019 08:26

Revisions

  1. dotdoom created this gist Mar 15, 2019.
    21 changes: 21 additions & 0 deletions main.dart
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    import 'dart:async';

    Future<void> b(value) async {
    await Future.delayed(Duration(seconds: 0));
    // OR: remove the line ABOVE for fun effect.
    print('b(${value})');
    }

    Future<void> a(value) async {
    print('a(${value})');
    scheduleMicrotask(() => b(value));
    // OR: replace scheduleMicrotask() with await b(value);
    return value + 1;
    }

    void main() {
    scheduleMicrotask(() => print('microtask1'));
    a(1).then(a).then(a);
    print('done');
    scheduleMicrotask(() => print('microtask2'));
    }