Skip to content

Commit

Permalink
fix(core): use scheduler instead of Promise.all on session creation
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Feb 26, 2021
1 parent 93c1508 commit 7d16d96
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 14 deletions.
6 changes: 4 additions & 2 deletions packages/core/lib/plugins/tools_find.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions packages/core/lib/session.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions packages/core/src/session.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ session = (action={}) ->
unless Array.isArray actions
session actions
else
# schl = schedule()
# Promise.all actions.map (action) ->
# schl.push -> session action
schedule actions.map (action) -> -> session action
new Proxy prom, get: on_get
# Building the namespace before calling an action
Expand Down Expand Up @@ -128,7 +125,7 @@ session = (action={}) ->
name: 'nikita:rejected'
args: action: action, error: err
# Returning a proxified promise:
# - news action can be registered to it as long as the promised has not fulfilled
# - new actions can be registered to it as long as the promised has not fulfilled
# - resolve when all registered actions are fulfilled
# - resolved with the result of handler
new Proxy result, get: on_get
Expand All @@ -137,5 +134,5 @@ module.exports = run = (...args) ->
actions = contextualize args
# Are we scheduling one or multiple actions
if Array.isArray actions
then Promise.all actions.map (action) -> session action
then schedule actions.map (action) -> -> session action
else session actions
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
nikita = require '../../../src'

describe 'session.handler.context', ->

it 'context config dont conflict', ->
nikita.call
context: true
Expand Down
20 changes: 20 additions & 0 deletions packages/core/test/session/creation.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

session = require '../../src/session'

describe 'session.creation', ->

describe 'args is array of actions', ->

it 'which succeed', ->
result = await session [
-> 1
-> 2
]
result.should.eql [1, 2]

it 'first throw error', ->
session [
-> throw Error 'Catchme'
-> true
]
.should.be.rejectedWith 'Catchme'

0 comments on commit 7d16d96

Please sign in to comment.