Created
June 11, 2012 05:02
-
-
Save vadimtsushko/2908587 to your computer and use it in GitHub Desktop.
Workaround. Still not works yet.
This file contains 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:io"); | |
Future getFuture() { | |
var completer = new Completer(); | |
new Timer(100,(timer) => completer.complete(true)); | |
return completer.future; | |
} | |
Future openSocket() { | |
var completer = new Completer(); | |
var result = completer.future; | |
result.handleException((exc) { | |
new Timer(0,(timer) { | |
print(exc); | |
return false; | |
}); | |
}); | |
Socket socket = new Socket('www.dartlang.org', 80); | |
if (socket is! Socket) { | |
completer.completeException(new Exception( "can't get send socket")); | |
} else { | |
socket.onError = (e) { | |
print("connect exception ${e}"); | |
completer.completeException(e); | |
}; | |
socket.onConnect = () { | |
completer.complete(socket); | |
}; | |
} | |
return result; | |
} | |
void main() { | |
openSocket().chain((_) { | |
print("Before exception in chain block"); | |
throw 'Error in chain block'; | |
print("After exception in chain block"); | |
return getFuture(); | |
}).then((_) { | |
print("Before exception in then block"); | |
throw 'Error in then block'; | |
print("After exception in then block"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment