<commit_before>// Copyright (c) 2016 by <NAME>. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.

package task

import (
	"sync"
)

var (
	nextInvocationID uint64 = 1
	dispatchMapLock  sync.Mutex
	dispatchMap      = make(map[uint64]func())
)

func Record(task func()) uint64 {
	dispatchMapLock.Lock()
	defer dispatchMapLock.Unlock()
	id := nextInvocationID
	nextInvocationID++
	dispatchMap[id] = task
	return id
}

func Dispatch(id uint64) {
	if f := remove(id); f != nil {
		f()
	}
}

func remove(id uint64) func() {
	dispatchMapLock.Lock()
	defer dispatchMapLock.Unlock()
	if f, ok := dispatchMap[id]; ok {
		delete(dispatchMap, id)
		return f
	}
	return nil
}<commit_msg>Cleanup<commit_after>// Copyright (c) 2016 by <NAME>. All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, version 2.0. If a copy of the MPL was not distributed with
// this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// This Source Code Form is "Incompatible With Secondary Licenses", as
// defined by the Mozilla Public License, version 2.0.

package task

import (
	"sync"
)

var (
	nextID uint64 = 1
	lock   sync.Mutex
	tasks  = make(map[uint64]func())
)

func Record(task func()) uint64 {
	if task == nil {
		panic("nil task not permitted")
	}
	lock.Lock()
	id := nextID
	nextID++
	tasks[id] = task
	lock.Unlock()
	return id
}

func Dispatch(id uint64) {
	lock.Lock()
	task := tasks[id]
	if task != nil {
		delete(tasks, id)
	}
	lock.Unlock()
	if task != nil {
		task()
	}
}
{'fraction_non_alphanumeric': 0.12486368593238822, 'fraction_numerical': 0.021810250817884406, 'mean_word_length': 3.4004796163069546, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1318359', 'n_tokens_mistral': 660, 'n_tokens_neox': 621, 'n_words': 223}