lukeed / taskr

A fast, concurrency-focused task automation tool.
MIT License
2.53k stars 75 forks source link

TypeError: A value [object Object] was yielded that could not be treated as a promise. #311

Closed BobbyBabes closed 5 years ago

BobbyBabes commented 5 years ago
[bobbybabes@ladyluck 4.4.23 ~]# echo -e '\n'; node -v; echo -e '\n\n'; npm -v; echo -e '\n\n'; bash --version; echo -e '\n\n';uname --all; echo -e '\n';

v10.8.0

6.3.0

GNU bash, version 4.4.23(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Linux ladyluck 4.17.11-arch1 #1 SMP PREEMPT Sun Jul 29 10:11:16 UTC 2018 x86_64 GNU/Linux

I only just discovered Taskr, and I'm running into this issue.

This API example snippet dies in function tryCatcher of Bluebird's util.js. When halted with a breakpoint on line 35 in the VS Code debugger, hitting F10 prints "first: 10" to the log and then transfers control to line 18 in function tryCatcher of Bluebird's util.js : errorObj.e = e;. And then program execution is halted. See screenshot for the detailed error message.


// Source : https://github.com/lukeed/taskr/tree/master/packages/taskr#options-2

// module.exports = {
//     *default(task) {
//       yield task.serial(['first', 'second'], { val:10 });
//     },
//     *first(task, opts) {
//       yield task.$.log(`first: ${opts.val}`);
//       return opts.val * 4;
//     },
//     *second(task, opts) {
//       yield task.$.log(`second: ${opts.val}`);
//       return opts.val + 2;
//     }
// }

// const output = yield task.start();​​ //"SyntaxError: Unexpected identifier". N.B. Of course, yield only in a generator.
  //=> first: 10
  //=> second: 40
// console.log(output);
  //=> 42

//==========================================================================================================================

const Taskr = require('taskr')
const taskr = new Taskr({
    tasks: {
        *default(task) {
            yield task.serial(['first', 'second'], { val:10 });
        },
        *first(task, opts) {
            const rtnVal = yield task.$.log(`first: ${opts.val}`);
            return opts.val * 4;
        },
        *second(task, opts) {
            const rtnVal = yield task.$.log(`second: ${opts.val}`);
            return opts.val + 2;
        }
    }
});

function * test() {
    const output = yield taskr.start();
    //=> first: 10
    //=> second: 40
    console.log(output);
    //=> 42
}

const iterator = test();

const result1 = iterator.next(); /*?*/
const result2 = iterator.next(); /*?*/

console.log('result1 : '); console.dir(result1);
console.log('result2 : '); console.dir(result2);

The exact same code is here in this Runkit Notebook : https://runkit.com/bobbybabes/taskr-bluebird-error If you run it, you can see that only "first: 10" is printed to the log (on the second page).

taskr-bluebird-error

lukeed commented 5 years ago

Hey sorry, I saw this over the weekend but forgot to reply to it! 🙈

Taskr runs on generators only. We have a @taakr/esnext package that rewrites the taskfile (only) from async to function*.

It looks like you're trying to rely on native async functions without the utility. In this current version of Taskr, that's not possible. Yet!

BobbyBabes commented 5 years ago

No problem. So Taskr becomes something to watch.