Skip to content

Documentation for Isolate.spawn outdated #50009

Closed
@mmcdon20

Description

@mmcdon20

This was noticed by a user on stackoverflow: https://stackoverflow.com/questions/73778870/is-dartdocs-about-the-entry-of-isolate-spawn-wrong-or-something

Currently the documentation says:

The function must be a top-level function or a static method that can be called with a single argument, that is, a compile-time constant function value which accepts at least one positional parameter and has at most one required positional parameter. The function may accept any number of optional parameters, as long as it can be called with just a single argument. The function must not be the value of a function expression or an instance method tear-off.

But it is possible now to pass a function expression or an instance method tear-off.

import 'dart:isolate';

void main() async {
  await Isolate.spawn((message) => print(message), 'function expression');
  await Isolate.spawn(MessagePrinter().printMessage, 'method tear-off');
}

class MessagePrinter {
  void printMessage(message) => print(message);
}

This appears to be possible since dart 2.15:

Allow closures both in inter-isolate messages as well as as entrypoints in Isolate.spawn(<entrypoint>, ...) calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-documentationPrefer using 'type-documentation' and a specific area label.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions