question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Limit for number of Tasks running in sequence?

See original GitHub issue

The number of Tasks that can be run in sequence seems to be limited by the max size of the function stack for the platform. Sample code:

import R from 'ramda';
import Task from 'data.task';
import monads from 'control.monads';

const COUNT = 10000;

const l = R.repeat(1, COUNT);

monads.sequence(Task,
                R.map(Task.of, l))
  .fork((err) => console.error(err),
        (res) => console.log(res));

will produce:

/home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:113
  return new Task(function(reject, resolve) {
                          ^

RangeError: Maximum call stack size exceeded
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:113:27
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12
    at /home/francisco/Documents/code/folktale/node_modules/data.task/lib/task.js:114:12

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Avaqcommented, Nov 11, 2017

@robotlolita It doesn’t use free monads directly, but the same principal. Every operation just builds up a structure (much resembling an AST) and fork is the interpreter of that structure.

fork uses the same trick that is used in ChainRec implementations, where everything is executed in a single while-loop that only breaks when the operation did not call back synchronously.

The second trick is the flattening of newly encountered AST’s. When we call a chain, for example, we (lazily) get back a new AST, which is flattened into the current one at runtime, allowing the while-loop to continue without having to break. This part makes it so even recursion is stack safe.

1reaction
Avaqcommented, Nov 11, 2017

Fluture implements ChainRec

Not just that. Almost all operations in Fluture are stack safe. ChainRec is really just there for interoperability. Just try to run the exact same code given above but using Fluture:

const R = require('ramda');
const Future = require('fluture');
const monads = require('control.monads');

const COUNT = 1000000; //I increased the number a little to make sure

const l = R.repeat(1, COUNT);

monads.sequence(Future,
                R.map(Future.of, l))
  .fork((err) => console.error(err),
        (res) => console.log(res));

On my i5 machine, after 2.8 seconds, we see:

[1,
 1,
 1,
 ...,
 1,
 1,
 ... 999900 more items]

This all happened in the same tick we called fork.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there a limit on Number of Task Sequences : r/SCCM - Reddit
The task sequence environment is only 32MB. TS policy, dependent policies, content locations, user variables, built-in variables and private ...
Read more >
Task sequence step limit? - TechNet - Microsoft
The correct answer to this question is, unknown. There is a size limit to the task sequence environment, which is 10Mb. I have...
Read more >
c# - How to limit the number of active Tasks running via the ...
I have some ConcurrentQueue that contain Action ( System.Action ). Each action in this queue need to run ( need to be called...
Read more >
resources - to limit the number of concurrently running tasks.
In this pattern, we use resources to limit the number of concurrently running tasks. By default, Ray tasks require 1 CPU each and...
Read more >
Limit number of tasks running in parallel in Server
It's not possible to limit the number of tasks that are running in parallel. However, it's possible to make one or more tasks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found