Skip to content

Commit

Permalink
rename top-level spawn -> main
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboyd committed Jan 24, 2020
1 parent 11be079 commit 25203c6
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ declare module "effection" {
context: Context;
}

export function spawn(operation: Operation): Context;
export function main(operation: Operation): Context;

export function fork(operation: Operation): Operation;

Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { fork, join } from './control';

import { ExecutionContext } from './context';

export function spawn(operation) {
export function main(operation) {
let top = new ExecutionContext();
top.enter(operation);
return top;
Expand Down
10 changes: 5 additions & 5 deletions tests/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import expect from 'expect';

import { spawn, fork, join } from '../src/index';
import { main, fork, join } from '../src/index';

describe('Async executon', () => {
describe('with asynchronously executing children', () => {
let execution, one, two, three;

beforeEach(() => {
execution = spawn(function* outer() {
execution = main(function* outer() {
one = yield fork();

two = yield fork();
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('Async executon', () => {
let execution, one, two, three, sync, boom;
beforeEach(() => {
boom = new Error('boom!');
execution = spawn(function*() {
execution = main(function*() {
one = yield fork();
two = yield fork();
yield function*() {
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('Async executon', () => {
describe('A parent that block, but also has an async child', () => {
let parent, child;
beforeEach(() => {
parent = spawn(function*() {
parent = main(function*() {
child = yield fork();
yield x => x;
});
Expand Down Expand Up @@ -286,7 +286,7 @@ describe('Async executon', () => {
describe('joining a fork', () => {
let root, child, getNumber;
beforeEach(() => {
root = spawn(function*() {
root = main(function*() {
child = yield fork(function*() {
getNumber = yield fork();
let number = yield join(getNumber);
Expand Down
8 changes: 4 additions & 4 deletions tests/controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import expect from 'expect';

import { spawn } from '../src/index';
import { main } from '../src/index';

import mock from 'jest-mock';

Expand All @@ -22,7 +22,7 @@ describe('Controlling execution', () => {
beforeEach(() => {
relinquish = mock.fn();

execution = spawn(function*() {
execution = main(function*() {
yield control;
});

Expand Down Expand Up @@ -70,7 +70,7 @@ describe('Controlling execution', () => {
describe('from an intermediate step in an execution', () => {
beforeEach(() => {
relinquish = mock.fn();
spawn(function* () {
main(function* () {
yield control;
yield ctl => ctl.resume();
});
Expand All @@ -86,7 +86,7 @@ describe('Controlling execution', () => {
describe('a release function that throws an error', () => {
beforeEach(() => {
relinquish = () => { throw new Error('this is a bug in the release control!'); };
spawn(function* () {
main(function* () {
yield control;
});
});
Expand Down
10 changes: 5 additions & 5 deletions tests/execution.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import expect from 'expect';
import mock from 'jest-mock';
import { spawn, join, fork } from '../src/index';
import { main, join, fork } from '../src/index';

describe('execution', () => {

describe('raw functions that resume immediately', () => {
let exec, exit;
beforeEach(() => {
exit = mock.fn();
exec = spawn(({ resume, ensure }) => {
exec = main(({ resume, ensure }) => {
ensure(exit);
resume(1234);
});
Expand All @@ -27,7 +27,7 @@ describe('execution', () => {
let exec, exit;
beforeEach(() => {
exit = mock.fn();
exec = spawn(({ fail, ensure }) => {
exec = main(({ fail, ensure }) => {
ensure(exit);
fail(new Error('boom!'));
});
Expand All @@ -49,7 +49,7 @@ describe('execution', () => {
let exec, resume, fail;

beforeEach(() => {
exec = spawn(join(spawn(context => ({ resume, fail } = context))));
exec = main(join(main(context => ({ resume, fail } = context))));
});
it('is still running', () => { //invariant
expect(exec.isRunning).toBe(true);
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('execution', () => {
let exec, resume, fail;

beforeEach(() => {
exec = spawn(fork(context => ({ resume, fail } = context)));
exec = main(fork(context => ({ resume, fail } = context)));
});

it('makes the external process waiting and blocking', () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/fork-as-promise.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import expect from 'expect';
import mock from 'jest-mock';

import { spawn, fork } from '../src/index';
import { main, fork } from '../src/index';

const HALT = expect.stringContaining('Interrupted');
async function suspend() {}
Expand All @@ -10,7 +10,7 @@ describe('forks as promises', () => {
let root, child, awaken;

beforeEach(async () => {
root = spawn(function*() {
root = main(function*() {
child = yield fork();
return yield ({ resume }) => awaken = resume;
});
Expand Down
10 changes: 5 additions & 5 deletions tests/generator-syntax.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import expect from 'expect';
import mock from 'jest-mock';

import { spawn } from '../src/index';
import { main } from '../src/index';

describe('Co-routine guarantees', () => {
let top, inner, error;
Expand All @@ -15,7 +15,7 @@ describe('Co-routine guarantees', () => {

finalizeTop = mock.fn();
finalizeMiddle = mock.fn();
top = spawn(function* top() {
top = main(function* top() {
try {
return yield function* middle() {
try {
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Co-routine guarantees', () => {
describe('deeply nested task that throws an error', () => {
let execution, error;
beforeEach(() => {
execution = spawn(function*() {
execution = main(function*() {
try {
return yield function*() {
return yield function*() {
Expand Down Expand Up @@ -162,7 +162,7 @@ describe('executing a generators', () => {
describe('nested inside generator functions', () => {
beforeEach(() => {

execution = spawn(function*() {
execution = main(function*() {
let one = yield function*() { return 1; };
let two = yield function*() { return 2; };
return yield add(one, two);
Expand All @@ -177,7 +177,7 @@ describe('executing a generators', () => {

describe('directly', () => {
beforeEach(() => {
execution = spawn(add(1, 2));
execution = main(add(1, 2));
});
it('computes the result just fine', () => {
expect(execution.isCompleted).toEqual(true);
Expand Down
4 changes: 2 additions & 2 deletions tests/promise-of.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import expect from 'expect';

import { spawn } from '../src/index';
import { main } from '../src/index';

describe('yielding on a promise', () => {
let execution, deferred, error;

beforeEach(() => {
error = undefined;
deferred = new Deferred();
execution = spawn(function*() {
execution = main(function*() {
try {
return yield deferred.promise;
} catch (e) {
Expand Down
4 changes: 2 additions & 2 deletions tests/root.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

import expect from 'expect';

import { spawn, fork } from '../src/index';
import { main, fork } from '../src/index';

describe('Root', () => {
let execution, child, grandchild;

beforeEach(() => {
execution = spawn(function* () {
execution = main(function* () {
child = yield fork(function*() {
grandchild = yield fork();
});
Expand Down
4 changes: 2 additions & 2 deletions tests/spawn.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import expect from 'expect';
import { spawn } from '../src/index';
import { main } from '../src/index';

describe('spawning operations', () => {
describe('with default resume/fail', () => {
let context, child, resolve, reject;
beforeEach(() => {
context = spawn(({ spawn }) => {
context = main(({ spawn }) => {
child = spawn(({ resume, fail }) => {
resolve = resume;
reject = fail;
Expand Down
14 changes: 7 additions & 7 deletions types/execute.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Context, Sequence, spawn, fork } from 'effection';
import { Context, Sequence, main, fork } from 'effection';

function* operation(): Sequence {}

let execution: Context;

execution = spawn(fork(operation));
execution = main(fork(operation));

execution = spawn(operation());
execution = main(operation());

execution = spawn(Promise.resolve("hello world"));
execution = main(Promise.resolve("hello world"));

execution = spawn(function*() {});
execution = main(function*() {});

execution = spawn(undefined);
execution = main(undefined);

execution = spawn(({ resume, fail, ensure, context }) => {
execution = main(({ resume, fail, ensure, context }) => {
context.id;
resume(10);
context.halt();
Expand Down
10 changes: 5 additions & 5 deletions types/promise.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { spawn } from 'effection';
import { main } from 'effection';

async function someAsyncFunction() {
await spawn(function*() {
await main(function*() {
yield
});

await Promise.all([
spawn(function*() { yield }),
spawn(function*() { yield }),
main(function*() { yield }),
main(function*() { yield }),
]);

let someFork = spawn(function*() {
let someFork = main(function*() {
yield
return 123;
});
Expand Down

0 comments on commit 25203c6

Please sign in to comment.