Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1.  
  2. import neko.Lib;
  3. import sys.FileSystem;
  4. import sys.io.File;
  5. import tink.core.Future;
  6. import tink.core.Outcome;
  7.  
  8. class FutureTriggerExample
  9. {
  10. static function main()
  11. {
  12. TxtLoaders.loadAll(['existing.txt', 'non-existing.txt']).handle(function(outcome) trace(outcome));
  13. }
  14. }
  15.  
  16. class TxtLoader {
  17. static public function load(url:String):Surprise<String, String> {
  18. var f = Future.trigger();
  19. if (FileSystem.exists(url))
  20. f.trigger(Success( File.getContent(url)))
  21. else
  22. f.trigger(Failure('Can\'t find $url'));
  23.  
  24. return f.asFuture();
  25. }
  26. }
  27.  
  28. class TxtLoaders {
  29. static public function loadAll(urls:Array<String>): Future<Array<Outcome<String, String>>> {
  30. return [ for (url in urls) TxtLoader.load(url) ];
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement