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
on run {input, parameters} | |
set output to "http://translate.google.com/#auto/en/" & urldecode(input as string) | |
return output | |
end run | |
on urldecode(x) | |
set cmd to "'require \"cgi\"; puts CGI.escape(STDIN.read.chomp)'" | |
do shell script "echo " & quoted form of x & " | ruby -e " & cmd | |
end urldecode |
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
async function publishAll() { | |
// You get the posts | |
const posts = await getPosts(); | |
const successes = []; | |
const failures = []; | |
for (const post of posts) { | |
// synchronous check for validtion | |
if (!validate(post)) { | |
failures.push({ post, status: "failed" }); | |
} else { |
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
async function publishPipeline(post){ | |
if (!validate(post)){ | |
return { post, status: "failed" }; | |
} | |
try { | |
await publish(post) | |
return { post, status: "published" }; | |
} catch (e) { | |
return { post, status: "failed", error: e }; | |
} |
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
async function publishAll() { | |
const payments = await getPayments(); | |
const invoices = await getInvoices(); | |
const receipts = await getReceipts(); | |
// do stuff with that | |
} |
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
async function publishAll() { | |
const [payments, invoices, receipts] = await Promise.all([ | |
getPayments(), | |
getInvoices(), | |
getReceipts() | |
]); | |
// do stuff with that | |
} |
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
import { buffers, channel } from "redux-saga"; | |
import { all, call, fork, put, take } from "redux-saga/effects"; | |
/** | |
* creates a queue | |
* | |
* @param {GeneratorFunction} [handler] request handler | |
* @param {number} [workersCount=1] number of workers | |
*/ | |
function* createConcurrentTaskQueue(handler, workersCount = 1) { |
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
function* handler({ uri, index, segmentsCount }) { | |
// get the data | |
const res = yield call(fetch, uri); | |
const blob = yield res.blob(); | |
// report to the store | |
yield put({ type: "CHUNK_DONE", payload: { index, blob } }) | |
// check if all the chunk are ready | |
const currentChunkCount = yield select(currentChunkCountSelector) |
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 QUEUE_CONCURRENT = 5 | |
const { watcher, queueChannel } = yield createConcurrentTaskQueue( | |
handler, | |
QUEUE_CONCURRENT | |
); | |
const watcherTask = yield fork(watcher) |
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 segmentsCount = segments.length | |
// transform the segments list to an action list | |
const actions = segments.map((segment, index) => | |
put(queueChannel, { payload: { uri: segment.uri, index, segmentsCount } }) | |
) | |
// fire them all together | |
yield all(actions); |
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
// the first to fire between "all done" and "cancel" | |
const { cancelDownload, allDone } = yield race({ | |
allDone: take(allDoneChannel), | |
cancelDownload: take("CANCEL_DOWNLOAD") | |
}); | |
// stop the queue manager | |
yield cancel(watcherTask); | |
// in case of cancellation just return; |