Skip to content

Commit

Permalink
ontm provides timeout times
Browse files Browse the repository at this point in the history
  • Loading branch information
rjrodger committed Jun 27, 2019
1 parent 45fd288 commit 2121af6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions gate-executor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2014-2016 Richard Rodger, MIT License */
/* Copyright (c) 2014-2019 Richard Rodger, MIT License */
'use strict'

// Core modules.
Expand Down Expand Up @@ -203,7 +203,7 @@ function GateExecutor(options, instance_counter) {

if (!work.gate && !work.done && work.tm < now - work.start) {
if (work.ontm) {
work.ontm(work.tm,now,work.start)
work.ontm(work.tm,work.start,now)
}

work.callback()
Expand Down Expand Up @@ -264,6 +264,7 @@ function GateExecutor(options, instance_counter) {
// * `id` (string): identifier for the work item. Optional.
// * `tm` (integer): millisecond timeout specific to this work item,
// overrides general timeout. Optional.
// * `ontm` (function): callback to indicate work item timeout. Optional.
// * `dn` (string): description of the work item, used in the
// state description. Optional.
self.add = function(work) {
Expand All @@ -280,6 +281,9 @@ function GateExecutor(options, instance_counter) {

work.dn = work.dn || work.fn.name || '' + Date.now()

// Used by calling code to store additional context.
work.ctxt = {}

q.push(work)

if (s.running) {
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"test": "lab -v -P test -t 100 --shuffle -L",
"annotate": "docco gate-executor.js -o doc",
"prettier": "prettier --write gate-executor.js",
"coveralls": "lab -s -P test -r lcov | coveralls"
"coveralls": "lab -s -P test -r lcov | coveralls",
"clean-npm": "rm -rf node_modules package-lock.json",
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags",
"repo-publish": "npm run prettier && npm test && npm run annotate && npm run repo-tag && npm publish --access public"

},
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions test/gate-executor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ describe('gate-executor', function () {

ge.add({
tm: 50,
ontm: function (timeout, now, start) {
log.push('t-dd:'+timeout+':'+(now-start>timeout?'P':'F'))
ontm: function (timeout, start, end) {
log.push('t-dd:'+timeout+':'+(end-start>timeout?'P':'F'))
},
fn: function dd (d) {
log.push('s-dd')
Expand Down

0 comments on commit 2121af6

Please sign in to comment.