Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add controller dispose #361

Merged
merged 1 commit into from
Jan 6, 2025
Merged

Add controller dispose #361

merged 1 commit into from
Jan 6, 2025

Conversation

ajthinking
Copy link
Owner

@ajthinking ajthinking commented Jan 6, 2025

Adds InputObserverController.dispose().
Useful to experiment with observers in headless code, like this example:

import { Application } from './Application'
import { coreNodeProvider } from './coreNodeProvider'
import { InMemoryStorage } from './InMemoryStorage'
import { InputObserverController } from './InputObserverController'
import { DiagramObserverStorage } from './storage/diagramObserverStorage'
import { ObserveLinkItems } from './types/ExecutionObserver'
import { RequestObserverType } from './types/InputObserveConfig'

(async () => {
  const app = new Application().register([coreNodeProvider])
  await app.boot()

  const diagram = app.getDiagramBuilder()
    .add('Signal', { count: 10})
    .add('Ignore')
    .connect()
    .get()

  const [ link ] = diagram.links

  const controller = new InputObserverController(
    new DiagramObserverStorage()
  )

  const linkObserver: ObserveLinkItems = {
    type: RequestObserverType.observeLinkItems,
    linkIds: [ link.id ],
    onReceive: (linksData) => {
      console.log('In onReceive!')
      console.log(linksData.map(l => `${l.linkId}: ${JSON.stringify(l.items)}`))
    },
    observerId: 'my-id',
  }

  controller.addLinkItemsObserver(linkObserver)

  const executor = app.getExecutor({
    diagram,
    storage: new InMemoryStorage(),
    inputObserverController: controller,
  })

  const execution = executor.execute()

  for await(const update of execution) {}
  console.log('Execution completed!')

  // without this line the script would never complete
  await controller.dispose()
  console.log('Controller disposed!')
})();

Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
data-story-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 6, 2025 4:03pm

@ajthinking ajthinking merged commit 8502133 into main Jan 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant