Last active
October 18, 2016 12:35
-
-
Save ryo33/a7103e0c75558131b724f4be0893fc2a to your computer and use it in GitHub Desktop.
This file contains 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
function* relay(request, relayChannel, nextChannel) { | |
const result = yield call(request) | |
yield put(relayChannel, [result, nextChannel]) | |
} | |
function* runSequencially(requestChannel, resultChannel) { | |
let head = channel() | |
let tail = head | |
while (true) { | |
const { request, relayResult } = yield race({ | |
request: take(requestChannel), | |
relayResult: take(head) | |
}) | |
if (request) { | |
const nextTail = channel() | |
yield fork(relay, request, tail, nextTail) | |
tail = nextTail | |
} else { | |
const [result, nextHead] = relayResult | |
yield put(resultChannel, result) | |
head = nextHead | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Code
Result