• Bob Nystrom's avatar
    Fix covariant overrides in SynchronousFuture. (#5262) · b504fd42
    Bob Nystrom authored
    * Fix covariant overrides in SynchronousFuture.
    
    There were two things going on here. In timeout(), the callback's return
    type was needlessly tightened to only allow callbacks that return
    futures. This makes SynchronousFuture not substitutable with Future,
    whose timeout() allows callbacks that return immediate values.
    
    Since SynchronousFuture.timeout() never calls the callback anyway, I
    just loosened it to match Future.timeout().
    
    SynchronousFuture.whenComplete() is just wrong. The type error, again,
    is that the callback's return type is too tight. Future.whenComplete()
    allows synchronous callbacks.
    
    But the actual implementation is wrong as well. whenComplete() should
    return a future that completes to the *original value*, not whatever the
    callback returns.
    
    So I just fixed the method to work correctly, including handling
    callbacks with synchronous results.
    
    * "(error, stackTrace)" -> "(e, stack)".
    b504fd42
synchronous_future.dart 1.81 KB