Skip to content

Instantly share code, notes, and snippets.

@lattner
lattner / TaskConcurrencyManifesto.md
Last active May 3, 2024 08:18
Swift Concurrency Manifesto
@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

'use strict';
var React = require('react-native');
var {
Bundler,
StyleSheet,
Text,
TouchableHighlight,
View,
ScrollView,
@appsandwich
appsandwich / gist:6007702
Created July 16, 2013 10:50
iOS - Simulate on-device memory warnings using volume button press
#if DEBUG
#import <MediaPlayer/MediaPlayer.h>
#endif
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if DEBUG
// Debug code that lets us simulate memory warnings by pressing the device's volume buttons.
@madrobby
madrobby / i18n.coffee
Created November 14, 2011 15:45
Backbone i18n with CoffeeScript
# before this file is loaded, a locale should be set:
#
# In a browser environment, you can use:
# ```<script>__locale='en';</script>```
#
# In a server environment (specifically node.js):
# ```global.__locale = 'en';```
# normalize in-app locale string to "en" or "de-AT"
parts = @__locale.split('-')
@bclinkinbeard
bclinkinbeard / gist:989706
Created May 24, 2011 21:13
Switch on type
var s:Sprite = new Sprite();
var mc:MovieClip = new MovieClip();
var b:Button = new Button();
var arr:Array = [ s, mc, b, this ];
for each( var obj:Object in arr )
{
switch( obj.constructor )
{
@darscan
darscan / or.js
Created May 9, 2011 13:49
And so I abandoned the Ruby to Node port after writing this:
Function.prototype.or = function(callback) {
var next = this;
return function(err, doc) {
if (err) {
callback(err, doc);
} else {
next(doc, callback);
}
};
};
@drewbourne
drewbourne / ColorizeTest.as
Created December 14, 2010 05:29
Colorize Flash trace() messages
package asx.string
{
public class ColorizeTest
{
var colors:Object = { red: red, green: green, yellow: yellow, blue: blue, purple: purple, cyan: cyan, gray: gray };
[Test]
public function colorize_shouldReturnColorizedString():void
{
for (var color:String in colors)
@jakemarsh
jakemarsh / gist:592329
Created September 22, 2010 19:28
Throw this on your UITableViewDelegate (probably your UITableViewController) to achieve the "keyboard dismisses when I tap away" effect.
//Throw this on your UITableViewDelegate (probably your UITableViewController) to achieve the "keyboard dismisses when I tap away" effect.
//Your users will thank you. A lot.
- (void) scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self.view endEditing:YES];
}
//The endEditing: method on UIView comes to us from a category that UITextField adds to UIKit that makes the view or any subview that is the first responder resign (optionally force), that's what the "YES" bit is.
function lineTowards(g:Graphics, x:int, y:int, length:int):void
{
var c:Number = Math.sqrt(Math.sqr(x) + Math.sqr(y));
var ratio:Number = length / c;
g.lineTo(x*ratio, y*ratio);
}