pogo : *r -> promise[r]
pogo(function*() {
yield sleep(1000)
const json = yield $.getJSON('/endpoint')
return json
This file contains hidden or 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
/* | |
* To run: | |
* npm install -g babel | |
* | |
* babel-node --stage 0 this-script.js | |
*/ | |
import fs from 'fs' | |
const mkDir = makePromisey(::fs.mkdir) |
This file contains hidden or 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
var path = require('path'); | |
var webpack = require('webpack'); | |
var config = module.exports = { | |
context: __dirname, | |
entry: './index.js', | |
output: { | |
path: path.join(__dirname, 'build'), | |
filename: 'index.js' | |
}, |
Idea: programming with a promise for an a
as if it were "more or less" an a
. That is, we don't want to have to change our programming style too much when transitioning from dealing with actual a
s to promises for a
s.
function lift(f) {
return function(...promises) {
return Promise.all(promises).then(values => f.apply(null, values))
}
}
This file contains hidden or 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
{-# OPTIONS_GHC -fwarn-incomplete-patterns #-} | |
{-# LANGUAGE NoMonomorphismRestriction #-} | |
module Generators where | |
import Prelude hiding (take, filter, foldr) | |
import Control.Applicative | |
import Control.Monad | |
import Control.Monad.Trans |
This file contains hidden or 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
'use strict'; | |
/* | |
* The trampoline. (Lots of inspiration taken from github.com/tj/co.) | |
*/ | |
function go(star, ...args) { | |
return new Promise((resolve, reject) => { | |
const gen = star.apply(null, args); | |
gen.resolve = resolve; |
Let's say we have the following schema:
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
This file contains hidden or 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
var path = require('path'); | |
var webpack = require('webpack'); | |
var config = module.exports = { | |
context: __dirname, | |
entry: './app/frontend/javascripts/entry.js', | |
output: { | |
path: path.join(__dirname, 'app', 'assets', 'javascripts'), | |
filename: 'bundle.js' | |
}, |
This file contains hidden or 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
const Promise = require('bluebird'); | |
const co = require('co'); | |
const React = require('react'); | |
function* sleep(ms) { | |
yield Promise.delay(ms); | |
} | |
function usersView(users) { | |
const lis = users.map(u => <li>{u.name}</li>); |