-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Fix some
Swift
methods not using the correct schedulers
- Loading branch information
Showing
5 changed files
with
200 additions
and
44 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const defStat = Blast.createStaticDefiner(Blast); | ||
const defStat = Blast.createStaticDefiner(Blast, true); | ||
|
||
/** | ||
* Turn the given list into a tree | ||
|
@@ -98,4 +98,36 @@ defStat(function createObjectId() { | |
result += count; | ||
|
||
return result; | ||
}); | ||
}); | ||
|
||
/** | ||
* Create the ASYNC_SCHEDULER symbol | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.7.21 | ||
* @version 0.7.21 | ||
* | ||
* @type {symbol} | ||
*/ | ||
defStat('asyncScheduler', Symbol('async_scheduler')); | ||
|
||
/** | ||
* Create the FLOW_PLEDGE symbol | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.8.15 | ||
* @version 0.8.15 | ||
* | ||
* @type {symbol} | ||
*/ | ||
defStat('flowPledgeClass', Symbol('flow_pledge_class')); | ||
|
||
/** | ||
* Call a function right now. | ||
* Meant to be used in response to setImmediate. | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.1.3 | ||
* @version 0.1.3 | ||
*/ | ||
defStat('callNow', fnc => fnc()); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,5 @@ | ||
const defStat = Blast.createStaticDefiner('Function'); | ||
|
||
/** | ||
* Create the ASYNC_SCHEDULER symbol | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.7.21 | ||
* @version 0.7.21 | ||
* | ||
* @type {symbol} | ||
*/ | ||
Blast.asyncScheduler = Symbol('async_scheduler'); | ||
|
||
/** | ||
* Create the FLOW_PLEDGE symbol | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.8.15 | ||
* @version 0.8.15 | ||
* | ||
* @type {symbol} | ||
*/ | ||
Blast.flowPledgeClass = Symbol('flow_pledge_class'); | ||
|
||
/** | ||
* Call a function right now. | ||
* Meant to be used in response to setImmediate. | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.1.3 | ||
* @version 0.1.3 | ||
*/ | ||
Blast.callNow = function callNow(fnc) { | ||
fnc(); | ||
}; | ||
|
||
/** | ||
* A dummy function | ||
* | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,20 +264,20 @@ AbstractPledge.setStatic(function hasPromiseInterface(obj) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.7.0 | ||
* @version 0.9.0 | ||
* @version 0.9.3 | ||
*/ | ||
AbstractPledge.setStatic(function done(promise, callback) { | ||
|
||
let result; | ||
|
||
if (!promise || !promise.then) { | ||
result = Pledge.resolve(promise); | ||
result = this.resolve(promise); | ||
result.done(callback); | ||
} else { | ||
result = Pledge.prototype.done.call(promise, callback); | ||
result = this.prototype.done.call(promise, callback); | ||
|
||
if (!result) { | ||
result = Pledge.resolve(); | ||
result = this.resolve(); | ||
} | ||
} | ||
|
||
|
@@ -312,7 +312,6 @@ AbstractPledge.setStatic(function cast(value) { | |
} | ||
|
||
return Pledge.resolve(value); | ||
|
||
}); | ||
|
||
/** | ||
|
@@ -1397,9 +1396,84 @@ SwiftObject[Blast.flowPledgeClass] = Swift; | |
SwiftObject[Blast.asyncScheduler] = Blast.callNow; | ||
Swift[FNC] = SwiftObject; | ||
|
||
/** | ||
* Do the given tasks in parallel | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.3 | ||
* @version 0.9.3 | ||
* | ||
* @param {*} tasks | ||
* | ||
* @return {Pledge.Swift|*} | ||
*/ | ||
Swift.setStatic(function parallel(tasks) { | ||
let result = SwiftObject.parallel(false, tasks); | ||
return Swift.execute(result); | ||
}); | ||
|
||
/** | ||
* Map the given variable | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.3 | ||
* @version 0.9.3 | ||
* | ||
* @param {Object|Array} input | ||
* @param {Function} task | ||
* | ||
* @return {Pledge.Swift|*} | ||
*/ | ||
Swift.setStatic(function map(input, task) { | ||
|
||
if (!input || typeof input != 'object') { | ||
return input; | ||
} | ||
|
||
let mapped; | ||
|
||
if (Array.isArray(input)) { | ||
mapped = input.map(task); | ||
} else { | ||
mapped = {}; | ||
|
||
for (let key in input) { | ||
mapped[key] = task(input[key], key); | ||
} | ||
} | ||
|
||
return Swift.parallel(mapped); | ||
}); | ||
|
||
/** | ||
* Cast the given value to a pledge | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 0.9.3 | ||
* @version 0.9.3 | ||
* | ||
* @param {Mixed} value | ||
* | ||
* @return {SwiftPledge} | ||
*/ | ||
Swift.setStatic(function cast(value) { | ||
|
||
if (!value || typeof value == 'function') { | ||
return Swift.resolve(value); | ||
} | ||
|
||
let result = Swift.execute(value); | ||
|
||
if (result && result instanceof Swift) { | ||
return result; | ||
} | ||
|
||
return Swift.resolve(result); | ||
}); | ||
|
||
/** | ||
* Execute the given function and return the value as swiftly as possible. | ||
* If no promise is returned, the value will be returned as is. | ||
* If no promise is given, the value will be returned as is. | ||
* If the given value is not a function, it will be returned as is. | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
|
@@ -1408,7 +1482,7 @@ Swift[FNC] = SwiftObject; | |
* | ||
* @param {Mixed} value | ||
* | ||
* @return {SwiftPledge|Mixed} | ||
* @return {Pledge.Swift|*} | ||
*/ | ||
Swift.setStatic(function execute(value) { | ||
|
||
|
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