effection
Advanced tools
Comparing version 0.3.3-00a19e9 to 0.3.3-541a371
@@ -148,2 +148,17 @@ 'use strict'; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
class Fork { | ||
@@ -210,2 +225,3 @@ get isUnstarted() { | ||
constructor(operation, parent, sync) { | ||
this.id = Fork.ids++; | ||
this.operation = toGeneratorFunction(operation); | ||
@@ -293,3 +309,2 @@ this.parent = parent; | ||
fork(operation, sync = false) { | ||
// console.log(`parent.fork(${operation}, ${sync})`); | ||
let child = new Fork(operation, this, sync); | ||
@@ -348,5 +363,16 @@ this.children.add(child); | ||
thunk(fn) { | ||
let next; | ||
let previouslyExecuting = Fork.currentlyExecuting; | ||
try { | ||
let next = this.enter(fn); | ||
Fork.currentlyExecuting = this; | ||
this.exitPrevious(); | ||
try { | ||
next = fn(this.iterator); | ||
} catch (error) { | ||
this.finalize('errored', error); | ||
return; | ||
} | ||
if (next.done) { | ||
@@ -364,14 +390,2 @@ if (this.hasBlockingChildren) { | ||
} | ||
} catch (error) { | ||
this.finalize('errored', error); | ||
} | ||
} | ||
enter(fn) { | ||
let previouslyExecuting = Fork.currentlyExecuting; | ||
try { | ||
Fork.currentlyExecuting = this; | ||
this.exitPrevious(); | ||
return fn(this.iterator); | ||
} finally { | ||
@@ -397,4 +411,14 @@ Fork.currentlyExecuting = previouslyExecuting; | ||
get root() { | ||
if (this.parent) { | ||
return this.parent.root; | ||
} else { | ||
return this; | ||
} | ||
} | ||
} | ||
_defineProperty(Fork, "ids", 0); | ||
function fork(operation, parent = Fork.currentlyExecuting) { | ||
@@ -401,0 +425,0 @@ if (parent) { |
@@ -0,1 +1,3 @@ | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import { noop } from "./noop.js"; | ||
@@ -46,2 +48,3 @@ import { promiseOf } from "./promise-of.js"; | ||
constructor(operation, parent, sync) { | ||
this.id = Fork.ids++; | ||
this.operation = toGeneratorFunction(operation); | ||
@@ -129,3 +132,2 @@ this.parent = parent; | ||
fork(operation, sync = false) { | ||
// console.log(`parent.fork(${operation}, ${sync})`); | ||
let child = new Fork(operation, this, sync); | ||
@@ -184,5 +186,16 @@ this.children.add(child); | ||
thunk(fn) { | ||
let next; | ||
let previouslyExecuting = Fork.currentlyExecuting; | ||
try { | ||
let next = this.enter(fn); | ||
Fork.currentlyExecuting = this; | ||
this.exitPrevious(); | ||
try { | ||
next = fn(this.iterator); | ||
} catch (error) { | ||
this.finalize('errored', error); | ||
return; | ||
} | ||
if (next.done) { | ||
@@ -200,14 +213,2 @@ if (this.hasBlockingChildren) { | ||
} | ||
} catch (error) { | ||
this.finalize('errored', error); | ||
} | ||
} | ||
enter(fn) { | ||
let previouslyExecuting = Fork.currentlyExecuting; | ||
try { | ||
Fork.currentlyExecuting = this; | ||
this.exitPrevious(); | ||
return fn(this.iterator); | ||
} finally { | ||
@@ -233,4 +234,14 @@ Fork.currentlyExecuting = previouslyExecuting; | ||
get root() { | ||
if (this.parent) { | ||
return this.parent.root; | ||
} else { | ||
return this; | ||
} | ||
} | ||
} | ||
_defineProperty(Fork, "ids", 0); | ||
export function fork(operation, parent = Fork.currentlyExecuting) { | ||
@@ -237,0 +248,0 @@ if (parent) { |
@@ -149,2 +149,17 @@ /** | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
class Fork { | ||
@@ -190,2 +205,3 @@ get isUnstarted() { | ||
constructor(operation, parent, sync) { | ||
this.id = Fork.ids++; | ||
this.operation = toGeneratorFunction(operation); | ||
@@ -260,3 +276,2 @@ this.parent = parent; | ||
let sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
// console.log(`parent.fork(${operation}, ${sync})`); | ||
let child = new Fork(operation, this, sync); | ||
@@ -301,5 +316,16 @@ this.children.add(child); | ||
thunk(fn) { | ||
let next; | ||
let previouslyExecuting = Fork.currentlyExecuting; | ||
try { | ||
let next = this.enter(fn); | ||
Fork.currentlyExecuting = this; | ||
this.exitPrevious(); | ||
try { | ||
next = fn(this.iterator); | ||
} catch (error) { | ||
this.finalize('errored', error); | ||
return; | ||
} | ||
if (next.done) { | ||
@@ -317,14 +343,2 @@ if (this.hasBlockingChildren) { | ||
} | ||
} catch (error) { | ||
this.finalize('errored', error); | ||
} | ||
} | ||
enter(fn) { | ||
let previouslyExecuting = Fork.currentlyExecuting; | ||
try { | ||
Fork.currentlyExecuting = this; | ||
this.exitPrevious(); | ||
return fn(this.iterator); | ||
} finally { | ||
@@ -350,4 +364,14 @@ Fork.currentlyExecuting = previouslyExecuting; | ||
get root() { | ||
if (this.parent) { | ||
return this.parent.root; | ||
} else { | ||
return this; | ||
} | ||
} | ||
} | ||
_defineProperty(Fork, "ids", 0); | ||
function fork(operation) { | ||
@@ -354,0 +378,0 @@ let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Fork.currentlyExecuting; |
@@ -9,2 +9,3 @@ declare module "effection" { | ||
export interface Execution<T = any> { | ||
id: number; | ||
resume(result: T): void; | ||
@@ -11,0 +12,0 @@ throw(error: Error): void; |
{ | ||
"name": "effection", | ||
"description": "Effortlessly composable structured concurrency primitive for JavaScript", | ||
"version": "0.3.3-00a19e9", | ||
"version": "0.3.3-541a371", | ||
"license": "MIT", | ||
@@ -20,2 +20,3 @@ "files": [ | ||
"@babel/core": "7.4.4", | ||
"@babel/plugin-proposal-class-properties": "^7.7.0", | ||
"@babel/preset-env": "7.4.4", | ||
@@ -22,0 +23,0 @@ "@babel/register": "7.4.4", |
40065
1056
18