-
-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathasync-arrow-runtime.js
32 lines (26 loc) · 972 Bytes
/
async-arrow-runtime.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { TaskFactory } from './task-factory';
/**
* This builder function is called by the transpiled code from
* `task(async () => {})`. See lib/babel-plugin-transform-ember-concurrency-async-tasks.js
*
* @private
*/
export function buildTask(contextFn, options, taskName, bufferPolicyName) {
let optionsWithBufferPolicy = options;
if (bufferPolicyName) {
optionsWithBufferPolicy = Object.assign({}, optionsWithBufferPolicy);
optionsWithBufferPolicy[bufferPolicyName] = true;
}
const result = contextFn();
if (optionsWithBufferPolicy && optionsWithBufferPolicy.waitFor) {
result.generator = optionsWithBufferPolicy.waitFor(result.generator);
optionsWithBufferPolicy = Object.assign({}, optionsWithBufferPolicy);
delete optionsWithBufferPolicy.waitFor;
}
const taskFactory = new TaskFactory(
taskName || '<unknown>',
result.generator,
optionsWithBufferPolicy
);
return taskFactory.createTask(result.context);
}