0.0.12 • Published 10 years ago

po-go v0.0.12

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago
import pogo, { chan, put } from './index.js'

const sleep = ms => new Promise(awaken => setTimeout(awaken, ms))

function* player(name, table) {
  while (true) {
    const ball = yield table
    console.log(`ball: ${ball}`)
    if (ball === "deflated") {
      console.log(`${name}: the ball popped :(`)
      return
    }
    ball.hits += 1
    yield sleep(100)
    yield put(table, ball)
  }
}

pogo(function* () {
  const table = chan()

  pogo(player(['ping', table])).catch(e => console.log('ping wtf:', e))
  pogo(player(['pong', table])).catch(e => console.log('pong wtf:', e))

  yield put(table, {hits: 0})
  yield sleep(1000)
  yield put(table, 'deflated')
}).catch(e => console.log('game wtf:', e));
0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago