Skip to content

Instantly share code, notes, and snippets.

View shammelburg's full-sized avatar

Sander Hammelburg shammelburg

View GitHub Profile
@shammelburg
shammelburg / Resource.swift
Created June 1, 2016 08:00 — forked from greglecki/Resource.swift
Generic way of loading data from the network.
struct Resource<A> {
let pathComponent: String
let parse: AnyObject -> A?
}
extension Resource {
func loadAsynchronous(callback: A? -> ()) {
let session = NSURLSession.sharedSession()
let resourceURL = webserviceURL.URLByAppendingPathComponent(pathComponent)
session.dataTaskWithURL(resourceURL) {
@shammelburg
shammelburg / Async Await with WhenAll.cs
Created April 14, 2016 13:36 — forked from greglecki/Async Await with WhenAll.cs
Bundle multiple asynchronous calls which helps with performance.
var testRepo = new TestRepo();
//var start = DateTime.Now;
var t1 = testRepo.Task1();
var t2 = testRepo.Task2();
int[] r = await Task.WhenAll(t1, t2);
//var end = (DateTime.Now - start).Seconds;
return new int[] { r[0], r[1] };
/***************************/
public class TestRepo